From 70b7f885f46a20c403f81ab3b3f7c314bae90735 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Tue, 16 Aug 2022 07:26:50 +0200 Subject: [PATCH] Add newsfragment for #997 --- changelog.d/997.change.rst | 2 ++ tests/typing_example.py | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelog.d/997.change.rst diff --git a/changelog.d/997.change.rst b/changelog.d/997.change.rst new file mode 100644 index 000000000..bc4b3de56 --- /dev/null +++ b/changelog.d/997.change.rst @@ -0,0 +1,2 @@ +``attrs.has()`` is now a ``TypeGuard`` for ``AttrsInstance``. +That means that type checkers know a class is an instance of an ``attrs`` class if you check it using ``attrs.has()`` (or ``attr.has()``) first. diff --git a/tests/typing_example.py b/tests/typing_example.py index c7ff5fb8d..a8228e596 100644 --- a/tests/typing_example.py +++ b/tests/typing_example.py @@ -418,7 +418,6 @@ def accessing_from_attrs() -> None: attrs.cmp_using -def has_typeguard() -> None: - foo = object - if attrs.has(foo): - foo.__attrs_attrs__ +foo = object +if attrs.has(foo) or attr.has(foo): + foo.__attrs_attrs__