-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flake8-pyi
] Various improvements to PYI034
#10807
Conversation
|
44da4ef
to
a7fbe73
Compare
.args | ||
.iter() | ||
.any(|expr| is_metaclass_base(expr, semantic)) | ||
analyze::class::any_qualified_name(class_def, semantic, &|qualified_name| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC this will recursively resolve subclasses (within the file). I'm not sure if that's intended in those case or not given the bullet in your PR summary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superclasses rather than subclasses, right? ;)
But yup, that's what I want! Sorry if theh PR summary was unclear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhh yes superclasses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, "The current logic" refers to main
, not the current logic of this PR. Of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
More accurately identify whether a class is a metaclass, a subclass of `collections.abc.Iterator`, or a subclass of `collections.abc.AsyncIterator`
Summary
Currently, the logic for PYI034 is pretty-much copied straight from the original Y034 implementation in flake8-pyi. As such, the implementation reflects the limited semantic analysis that flake8-pyi is capable of -- but Ruff, with its more sophisticated semantic model, can do better here.
Specific improvements made:
is_metaclass
now recognises that subclasses of subclasses oftype
/enum.EnumMeta
/abc.ABCMeta
are also metaclasses. (The current logic only recognises direct subclasses of these subclasses as being metaclasses. Any metaclass should be excluded from PYI034, as PEP 673 specifies that no methods in metaclasses may useSelf
in annotations.)Iterator[T]
are also flagged if their__iter__
methods are annotated as returningIterator[T]
rather thanSelf
. Currently only direct subclasses ofIterator
are flagged.AsyncIterator[T]
are also flagged if their__aiter__
methods are annotated as returningAsyncIterator[T]
rather thanSelf
. Currently only direct subclasses ofAsyncIterator
are flagged.Test Plan
cargo test
.