From ecdb117407e98dba37515e54894ed7feef2df333 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sun, 4 Jun 2023 11:27:09 +0200 Subject: [PATCH] Fix type annotation for resolve_types() (#1141) --- changelog.d/1141.change.md | 1 + src/attr/__init__.pyi | 3 +-- tests/typing_example.py | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelog.d/1141.change.md diff --git a/changelog.d/1141.change.md b/changelog.d/1141.change.md new file mode 100644 index 00000000..8112504c --- /dev/null +++ b/changelog.d/1141.change.md @@ -0,0 +1 @@ +The type annotation for `attrs.resolve_types()` is now correct. diff --git a/src/attr/__init__.pyi b/src/attr/__init__.pyi index ced5a3fd..51d1af3a 100644 --- a/src/attr/__init__.pyi +++ b/src/attr/__init__.pyi @@ -69,8 +69,7 @@ _ValidatorArgType = Union[_ValidatorType[_T], Sequence[_ValidatorType[_T]]] class AttrsInstance(AttrsInstance_, Protocol): pass -_A = TypeVar("_A", bound=AttrsInstance) -# _make -- +_A = TypeVar("_A", bound=type[AttrsInstance]) class _Nothing(enum.Enum): NOTHING = enum.auto() diff --git a/tests/typing_example.py b/tests/typing_example.py index 5f5f79ab..9ffb92b4 100644 --- a/tests/typing_example.py +++ b/tests/typing_example.py @@ -468,3 +468,8 @@ if attrs.has(foo) or attr.has(foo): @attrs.define(unsafe_hash=True) class Hashable: pass + + +def test(cls: type) -> None: + if attr.has(cls): + attr.resolve_types(cls)