Skip to content

Commit fd2c819

Browse files
committed
fixup! Use TypeGuard for has in Python 3.10 and above
1 parent d824f72 commit fd2c819

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/attr/__init__.pyi

+7-9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ from . import validators as validators
2727
from ._cmp import cmp_using as cmp_using
2828
from ._version_info import VersionInfo
2929

30+
31+
if sys.version_info >= (3, 10):
32+
from typing import TypeGuard
33+
else:
34+
from typing_extensions import TypeGuard
35+
3036
__version__: str
3137
__version_info__: VersionInfo
3238
__title__: str
@@ -470,15 +476,7 @@ def astuple(
470476
tuple_factory: Type[Sequence[Any]] = ...,
471477
retain_collection_types: bool = ...,
472478
) -> Tuple[Any, ...]: ...
473-
474-
if sys.version_info >= (3, 10):
475-
from typing import TypeGuard
476-
477-
def has(cls: type) -> TypeGuard[Type[AttrsInstance]]: ...
478-
479-
else:
480-
def has(cls: type) -> bool: ...
481-
479+
def has(cls: type) -> TypeGuard[Type[AttrsInstance]]: ...
482480
def assoc(inst: _T, **changes: Any) -> _T: ...
483481
def evolve(inst: _T, **changes: Any) -> _T: ...
484482

tests/test_mypy.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,6 @@
13731373
fields(A) # E: Argument 1 to "fields" has incompatible type "Type[A]"; expected "Type[AttrsInstance]"
13741374
13751375
- case: testHasTypeGuard
1376-
skip: sys.version_info < (3, 10)
13771376
main: |
13781377
from attrs import define, has
13791378

0 commit comments

Comments
 (0)