[flake8-pyi] Various improvements to PYI034#10807
Merged
AlexWaygood merged 1 commit intoastral-sh:mainfrom Apr 6, 2024
Merged
Conversation
Contributor
|
44da4ef to
a7fbe73
Compare
| .args | ||
| .iter() | ||
| .any(|expr| is_metaclass_base(expr, semantic)) | ||
| analyze::class::any_qualified_name(class_def, semantic, &|qualified_name| { |
Member
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
Superclasses rather than subclasses, right? ;)
But yup, that's what I want! Sorry if theh PR summary was unclear
Member
There was a problem hiding this comment.
Oh right, "The current logic" refers to main, not the current logic of this PR. Of course.
Glyphack
pushed a commit
to Glyphack/ruff
that referenced
this pull request
Apr 12, 2024
More accurately identify whether a class is a metaclass, a subclass of `collections.abc.Iterator`, or a subclass of `collections.abc.AsyncIterator`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_metaclassnow recognises that subclasses of subclasses oftype/enum.EnumMeta/abc.ABCMetaare 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 useSelfin annotations.)Iterator[T]are also flagged if their__iter__methods are annotated as returningIterator[T]rather thanSelf. Currently only direct subclasses ofIteratorare flagged.AsyncIterator[T]are also flagged if their__aiter__methods are annotated as returningAsyncIterator[T]rather thanSelf. Currently only direct subclasses ofAsyncIteratorare flagged.Test Plan
cargo test.