Skip to content

Commit

Permalink
fixup! Use TypeGuard for has in Python 3.10 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed Aug 15, 2022
1 parent d824f72 commit fd2c819
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/attr/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ from . import validators as validators
from ._cmp import cmp_using as cmp_using
from ._version_info import VersionInfo


if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing_extensions import TypeGuard

__version__: str
__version_info__: VersionInfo
__title__: str
Expand Down Expand Up @@ -470,15 +476,7 @@ def astuple(
tuple_factory: Type[Sequence[Any]] = ...,
retain_collection_types: bool = ...,
) -> Tuple[Any, ...]: ...

if sys.version_info >= (3, 10):
from typing import TypeGuard

def has(cls: type) -> TypeGuard[Type[AttrsInstance]]: ...

else:
def has(cls: type) -> bool: ...

def has(cls: type) -> TypeGuard[Type[AttrsInstance]]: ...
def assoc(inst: _T, **changes: Any) -> _T: ...
def evolve(inst: _T, **changes: Any) -> _T: ...

Expand Down
1 change: 0 additions & 1 deletion tests/test_mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,6 @@
fields(A) # E: Argument 1 to "fields" has incompatible type "Type[A]"; expected "Type[AttrsInstance]"
- case: testHasTypeGuard
skip: sys.version_info < (3, 10)
main: |
from attrs import define, has
Expand Down

0 comments on commit fd2c819

Please sign in to comment.