-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix bug where Y019 was not emitted on methods that use PEP-695 TypeVars #402
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,68 @@ | ||
# Temporary workaround until pyflakes supports PEP 695: | ||
# flags: --extend-ignore=F821 | ||
|
||
import typing | ||
from collections.abc import Iterator | ||
from typing import Any, NamedTuple, NoReturn, Protocol, Self, TypedDict | ||
|
||
type lowercase_alias = str | int # Y042 Type aliases should use the CamelCase naming convention | ||
type _LooksLikeATypeVarT = str | int # Y043 Bad name for a type alias (the "T" suffix implies a TypeVar) | ||
type _Unused = str | int # Y047 Type alias "_Unused" is not used | ||
# the F821 here is a pyflakes false positive; | ||
# we can get rid of it when there's a pyflakes release that supports PEP 695 | ||
type _List[T] = list[T] # F821 undefined name 'T' | ||
type _List[T] = list[T] | ||
|
||
y: _List[int] | ||
|
||
x: _LooksLikeATypeVarT | ||
|
||
class GenericPEP695Class[T]: | ||
def __init__(self, x: int) -> None: | ||
self.x = x # Y010 Function body must contain only "..." | ||
def __new__(cls, *args: Any, **kwargs: Any) -> GenericPEP695Class: ... # Y034 "__new__" methods usually return "self" at runtime. Consider using "typing_extensions.Self" in "GenericPEP695Class.__new__", e.g. "def __new__(cls, *args: Any, **kwargs: Any) -> Self: ..." | ||
def __repr__(self) -> str: ... # Y029 Defining __repr__ or __str__ in a stub is almost always redundant | ||
def __eq__(self, other: Any) -> bool: ... # Y032 Prefer "object" to "Any" for the second parameter in "__eq__" methods | ||
def method(self) -> T: ... | ||
... # Y013 Non-empty class body must not contain "..." | ||
pass # Y012 Class body must not contain "pass" | ||
def __exit__(self, *args: Any) -> None: ... # Y036 Badly defined __exit__ method: Star-args in an __exit__ method should be annotated with "object", not "Any" | ||
async def __aexit__(self) -> None: ... # Y036 Badly defined __aexit__ method: If there are no star-args, there should be at least 3 non-keyword-only args in an __aexit__ method (excluding "self") | ||
def never_call_me(self, arg: NoReturn) -> None: ... # Y050 Use "typing_extensions.Never" instead of "NoReturn" for argument annotations | ||
|
||
class GenericPEP695InheritingFromObject[T](object): # Y040 Do not inherit from "object" explicitly, as it is redundant in Python 3 | ||
x: T | ||
|
||
class GenericPEP695InheritingFromIterator[T](Iterator[T]): | ||
def __iter__(self) -> Iterator[T]: ... # Y034 "__iter__" methods in classes like "GenericPEP695InheritingFromIterator" usually return "self" at runtime. Consider using "typing_extensions.Self" in "GenericPEP695InheritingFromIterator.__iter__", e.g. "def __iter__(self) -> Self: ..." | ||
|
||
class PEP695BadBody[T]: | ||
pass # Y009 Empty body should contain "...", not "pass" | ||
|
||
class PEP695Docstring[T]: | ||
"""Docstring""" # Y021 Docstrings should not be included in stubs | ||
... # Y013 Non-empty class body must not contain "..." | ||
|
||
class PEP695BadDunderNew[T]: | ||
def __new__[S](cls: type[S], *args: Any, **kwargs: Any) -> S: ... # Y019 Use "typing_extensions.Self" instead of "S", e.g. "def __new__(cls, *args: Any, **kwargs: Any) -> Self: ..." | ||
def generic_instance_method[S](self: S) -> S: ... # Y019 Use "typing_extensions.Self" instead of "S", e.g. "def generic_instance_method(self) -> Self: ..." | ||
|
||
class PEP695GoodDunderNew[T]: | ||
def __new__(cls, *args: Any, **kwargs: Any) -> Self: ... | ||
|
||
class GenericNamedTuple[T](NamedTuple): | ||
foo: T | ||
|
||
class GenericTypedDict[T](TypedDict): | ||
foo: T | ||
|
||
class GenericTypingDotNamedTuple(typing.NamedTuple): | ||
foo: T | ||
|
||
class GenericTypingDotTypedDict(typing.TypedDict): | ||
foo: T | ||
|
||
type NoDuplicatesInThisUnion = GenericPEP695Class[str] | GenericPEP695Class[int] | ||
type ThisHasDuplicates = GenericPEP695Class[str] | GenericPEP695Class[str] # Y016 Duplicate union member "GenericPEP695Class[str]" | ||
|
||
class _UnusedPEP695Protocol[T](Protocol): # Y046 Protocol "_UnusedPEP695Protocol" is not used | ||
x: T | ||
|
||
class _UnusedPEP695TypedDict[T](TypedDict): # Y049 TypedDict "_UnusedPEP695TypedDict" is not used | ||
x: T |
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.
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.
Y019 is not emitted on these two methods on
main