Skip to content
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

4.12.1: pyupgrade --py38-plus generated patch causes pytest fails #420

Closed
kloczek opened this issue Jun 2, 2024 · 9 comments
Closed

4.12.1: pyupgrade --py38-plus generated patch causes pytest fails #420

kloczek opened this issue Jun 2, 2024 · 9 comments

Comments

@kloczek
Copy link

kloczek commented Jun 2, 2024

Here is the patch

--- a/src/_typed_dict_test_helper.py
+++ b/src/_typed_dict_test_helper.py
@@ -16,7 +16,7 @@


 class FooGeneric(TypedDict, Generic[T]):
-    a: Optional[T]
+    a: T | None


 class VeryAnnotated(TypedDict, total=False):
--- a/src/test_typing_extensions.py
+++ b/src/test_typing_extensions.py
@@ -27,31 +27,17 @@
 from typing_extensions import (
     Annotated,
     Any,
-    AnyStr,
-    AsyncContextManager,
-    AsyncIterator,
-    Awaitable,
     Buffer,
-    Callable,
-    ClassVar,
     Concatenate,
-    Dict,
     Doc,
-    Final,
-    Generic,
     IntVar,
-    Iterable,
-    Iterator,
-    List,
     Literal,
     LiteralString,
     NamedTuple,
     Never,
     NewType,
     NoDefault,
-    NoReturn,
     NotRequired,
-    Optional,
     ParamSpec,
     ParamSpecArgs,
     ParamSpecKwargs,
@@ -59,9 +45,6 @@
     ReadOnly,
     Required,
     Self,
-    Set,
-    Tuple,
-    Type,
     TypeAlias,
     TypeAliasType,
     TypedDict,
@@ -69,7 +52,6 @@
     TypeIs,
     TypeVar,
     TypeVarTuple,
-    Union,
     Unpack,
     assert_never,
     assert_type,
@@ -85,13 +67,12 @@
     get_type_hints,
     is_protocol,
     is_typeddict,
-    no_type_check,
     overload,
     override,
     reveal_type,
     runtime,
-    runtime_checkable,
 )
+from typing import AnyStr, AsyncContextManager, AsyncIterator, Awaitable, Callable, ClassVar, Dict, Final, Generic, Iterable, Iterator, List, NoReturn, Optional, Set, Tuple, Type, Union, no_type_check, runtime_checkable

 NoneType = type(None)
 T = TypeVar("T")
@@ -3787,7 +3768,9 @@

 class TypedDictTests(BaseTestCase):
     def test_basics_functional_syntax(self):
-        Emp = TypedDict('Emp', {'name': str, 'id': int})
+        class Emp(TypedDict):
+            name: str
+            id: int
         self.assertIsSubclass(Emp, dict)
         self.assertIsSubclass(Emp, typing.MutableMapping)
         self.assertNotIsSubclass(Emp, collections.abc.Sequence)
@@ -3809,7 +3792,9 @@
     @skipIf(sys.version_info >= (3, 13), "3.13 removes support for kwargs")
     def test_basics_keywords_syntax(self):
         with self.assertWarns(DeprecationWarning):
-            Emp = TypedDict('Emp', name=str, id=int)
+            class Emp(TypedDict):
+                name: str
+                id: int
         self.assertIsSubclass(Emp, dict)
         self.assertIsSubclass(Emp, typing.MutableMapping)
         self.assertNotIsSubclass(Emp, collections.abc.Sequence)
@@ -3826,8 +3811,13 @@
     @skipIf(sys.version_info >= (3, 13), "3.13 removes support for kwargs")
     def test_typeddict_special_keyword_names(self):
         with self.assertWarns(DeprecationWarning):
-            TD = TypedDict("TD", cls=type, self=object, typename=str, _typename=int,
-                           fields=list, _fields=dict)
+            class TD(TypedDict):
+                cls: type
+                self: object
+                typename: str
+                _typename: int
+                fields: list
+                _fields: dict
         self.assertEqual(TD.__name__, 'TD')
         self.assertEqual(TD.__annotations__, {'cls': type, 'self': object, 'typename': str,
                                               '_typename': int, 'fields': list, '_fields': dict})
@@ -3849,7 +3839,9 @@
             TypedDict('Emp', [('name', str)], None)

     def test_typeddict_errors(self):
-        Emp = TypedDict('Emp', {'name': str, 'id': int})
+        class Emp(TypedDict):
+            name: str
+            id: int
         self.assertEqual(TypedDict.__module__, 'typing_extensions')
         jim = Emp(name='Jim', id=1)
         with self.assertRaises(TypeError):
@@ -3882,7 +3874,9 @@

     def test_pickle(self):
         global EmpD  # pickle wants to reference the class by name
-        EmpD = TypedDict('EmpD', {'name': str, 'id': int})
+        class EmpD(TypedDict):
+            name: str
+            id: int
         jane = EmpD({'name': 'jane', 'id': 37})
         for proto in range(pickle.HIGHEST_PROTOCOL + 1):
             z = pickle.dumps(jane, proto)
@@ -3905,13 +3899,16 @@
             self.assertEqual(Point2DGenericNew({'a': 5.0, 'b': 3.0}), point)

     def test_optional(self):
-        EmpD = TypedDict('EmpD', {'name': str, 'id': int})
+        class EmpD(TypedDict):
+            name: str
+            id: int

         self.assertEqual(typing.Optional[EmpD], typing.Union[None, EmpD])
         self.assertNotEqual(typing.List[EmpD], typing.Tuple[EmpD])

     def test_total(self):
-        D = TypedDict('D', {'x': int}, total=False)
+        class D(TypedDict, total=False):
+            x: int
         self.assertEqual(D(), {})
         self.assertEqual(D(x=1), {'x': 1})
         self.assertEqual(D.__total__, False)
@@ -4006,7 +4003,8 @@
             two: str
         class Untotal(TypedDict, total=False):
             untotal: str
-        Inline = TypedDict('Inline', {'inline': bool})
+        class Inline(TypedDict):
+            inline: bool
         class Regular:
             pass

@@ -4110,7 +4108,8 @@
         self.assertIs(is_typeddict(Union[str, int]), False)
         # classes, not instances
         self.assertIs(is_typeddict(Point2D()), False)
-        call_based = TypedDict('call_based', {'a': int})
+        class call_based(TypedDict):
+            a: int
         self.assertIs(is_typeddict(call_based), True)
         self.assertIs(is_typeddict(call_based()), False)

@@ -4138,7 +4137,9 @@
             self.assertIs(is_typeddict(typing.TypedDict), False)

     def test_is_typeddict_against_typeddict_from_typing(self):
-        Point = typing.TypedDict('Point', {'x': int, 'y': int})
+        class Point(typing.TypedDict):
+            x: int
+            y: int

         class PointDict2D(typing.TypedDict):
             x: int
@@ -4588,7 +4589,8 @@
     )
     def test_backwards_compatibility(self):
         with self.assertWarns(DeprecationWarning):
-            TD = TypedDict("TD", closed=int)
+            class TD(TypedDict):
+                closed: int
         self.assertFalse(TD.__closed__)
         self.assertEqual(TD.__annotations__, {"closed": int})

@@ -6842,7 +6844,8 @@
                 class GenericTypedDict(TypedDict, Generic[T]):
                     x: T

-                CallBasedTypedDict = TypedDict("CallBasedTypedDict", {"x": int})
+                class CallBasedTypedDict(TypedDict):
+                    x: int

                 self.assertIs(
                     get_original_bases(ClassBasedTypedDict)[0],
--- a/src/typing_extensions.py
+++ b/src/typing_extensions.py
@@ -413,7 +413,7 @@
 OrderedDict = typing.OrderedDict
 Counter = typing.Counter
 ChainMap = typing.ChainMap
-Text = typing.Text
+Text = str
 TYPE_CHECKING = typing.TYPE_CHECKING

As in pyproject.toml is requires-python = ">=3.8" it would be good to make current code pyupgrade ready (for --py3{9,10,11,12}-plus as well or report to pyupgrade that it messes something on filtering the code.

@kloczek
Copy link
Author

kloczek commented Jun 2, 2024

And it causes that pytest fails

Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-typing-extensions-4.12.1-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-typing-extensions-4.12.1-2.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.14, pytest-8.2.1, pluggy-1.5.0
rootdir: /home/tkloczko/rpmbuild/BUILD/typing_extensions-4.12.1
configfile: pyproject.toml
collected 434 items

src/test_typing_extensions.py ..............................................................................................................................................F..sF..FF [ 34%]
FFF........F......FF....FFFF.FFF.FFF...F...........FF..FF..F.FF..FF.F..............s......s.........F................s............................................................... [ 76%]
.................................s..s...s......................s.s...ss...s...........................                                                                                [100%]

========================================================================================= FAILURES ==========================================================================================
_____________________________________________________________________________ ProtocolTests.test_basic_protocol _____________________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_basic_protocol>

    def test_basic_protocol(self):
        @runtime_checkable
        class P(Protocol):
            def meth(self):
                pass
        class C: pass
        class D:
            def meth(self):
                pass
        def f():
            pass
>       self.assertIsSubclass(D, P)

src/test_typing_extensions.py:2056:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_basic_protocol.<locals>.P'>, other = <class 'test_typing_extensions.ProtocolTests.test_basic_protocol.<locals>.D'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
_____________________________________________________________________ ProtocolTests.test_collections_protocols_allowed ______________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_collections_protocols_allowed>

    def test_collections_protocols_allowed(self):
        @runtime_checkable
        class Custom(collections.abc.Iterable, Protocol):
            def close(self): pass

        class A: ...
        class B:
            def __iter__(self):
                return []
            def close(self):
                return 0

>       self.assertIsSubclass(B, Custom)

src/test_typing_extensions.py:3378:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_collections_protocols_allowed.<locals>.Custom'>
other = <class 'test_typing_extensions.ProtocolTests.test_collections_protocols_allowed.<locals>.B'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'Custom' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
_________________________________________________________________________ ProtocolTests.test_custom_subclasshook_2 __________________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_custom_subclasshook_2>

    @skipIf(
        sys.version_info[:4] == (3, 12, 0, 'beta') and sys.version_info[4] < 4,
        "Early betas of Python 3.12 had a bug"
    )
    def test_custom_subclasshook_2(self):
        @runtime_checkable
        class HasX(Protocol):
            # The presence of a non-callable member
            # would mean issubclass() checks would fail with TypeError
            # if it weren't for the custom `__subclasshook__` method
            x = 1

            @classmethod
            def __subclasshook__(cls, other):
                return hasattr(other, 'x')

        class Empty: pass

        class ImplementsHasX:
            x = 1

        self.assertIsInstance(ImplementsHasX(), HasX)
        self.assertNotIsInstance(Empty(), HasX)
>       self.assertIsSubclass(ImplementsHasX, HasX)

src/test_typing_extensions.py:3091:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_custom_subclasshook_2.<locals>.HasX'>
other = <class 'test_typing_extensions.ProtocolTests.test_custom_subclasshook_2.<locals>.ImplementsHasX'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'HasX' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
_______________________________________________________________________ ProtocolTests.test_defining_generic_protocols _______________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_defining_generic_protocols>

    def test_defining_generic_protocols(self):
        T = TypeVar('T')
        S = TypeVar('S')
        @runtime_checkable
        class PR(Protocol[T, S]):
            def meth(self): pass
        class P(PR[int, T], Protocol[T]):
            y = 1
        with self.assertRaises(TypeError):
>           issubclass(PR[int, T], PR)

src/test_typing_extensions.py:3145:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'PR' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
__________________________________________________________________ ProtocolTests.test_defining_generic_protocols_old_style __________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_defining_generic_protocols_old_style>

    def test_defining_generic_protocols_old_style(self):
        T = TypeVar('T')
        S = TypeVar('S')
        @runtime_checkable
        class PR(Protocol, Generic[T, S]):
            def meth(self): pass
        class P(PR[int, str], Protocol):
            y = 1
        with self.assertRaises(TypeError):
>           self.assertIsSubclass(PR[int, str], PR)

src/test_typing_extensions.py:3169:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'PR' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
__________________________________________________________________ ProtocolTests.test_empty_protocol_decorated_with_final ___________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_empty_protocol_decorated_with_final>

    def test_empty_protocol_decorated_with_final(self):
        @final
        @runtime_checkable
        class EmptyProtocol(Protocol): ...

>       self.assertIsSubclass(object, EmptyProtocol)

src/test_typing_extensions.py:3633:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_empty_protocol_decorated_with_final.<locals>.EmptyProtocol'>, other = <class 'object'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'EmptyProtocol' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
__________________________________________________________________ ProtocolTests.test_everything_implements_empty_protocol __________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_everything_implements_empty_protocol>

    def test_everything_implements_empty_protocol(self):
        @runtime_checkable
        class Empty(Protocol): pass
        class C: pass
        def f():
            pass
        for thing in (object, type, tuple, C, types.FunctionType):
>           self.assertIsSubclass(thing, Empty)

src/test_typing_extensions.py:2070:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_everything_implements_empty_protocol.<locals>.Empty'>, other = <class 'object'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'Empty' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
_______________________________________________________________ ProtocolTests.test_implicit_issubclass_between_two_protocols ________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_implicit_issubclass_between_two_protocols>

    def test_implicit_issubclass_between_two_protocols(self):
        @runtime_checkable
        class CallableMembersProto(Protocol):
            def meth(self): ...

        # All the below protocols should be considered "subclasses"
        # of CallableMembersProto at runtime,
        # even though none of them explicitly subclass CallableMembersProto

        class IdenticalProto(Protocol):
            def meth(self): ...

        class SupersetProto(Protocol):
            def meth(self): ...
            def meth2(self): ...

        class NonCallableMembersProto(Protocol):
            meth: Callable[[], None]

        class NonCallableMembersSupersetProto(Protocol):
            meth: Callable[[], None]
            meth2: Callable[[str, int], bool]

        class MixedMembersProto1(Protocol):
            meth: Callable[[], None]
            def meth2(self): ...

        class MixedMembersProto2(Protocol):
            def meth(self): ...
            meth2: Callable[[str, int], bool]

        for proto in (
            IdenticalProto, SupersetProto, NonCallableMembersProto,
            NonCallableMembersSupersetProto, MixedMembersProto1, MixedMembersProto2
        ):
            with self.subTest(proto=proto.__name__):
>               self.assertIsSubclass(proto, CallableMembersProto)

src/test_typing_extensions.py:2371:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_implicit_issubclass_between_two_protocols.<locals>.CallableMembersProto'>
other = <class 'test_typing_extensions.ProtocolTests.test_implicit_issubclass_between_two_protocols.<locals>.IdenticalProto'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'CallableMembersProto' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
______________________________________________________________ ProtocolTests.test_issubclass_and_isinstance_on_Protocol_itself ______________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_issubclass_and_isinstance_on_Protocol_itself>

    @skip_if_py312b1
    def test_issubclass_and_isinstance_on_Protocol_itself(self):
        class C:
            def x(self): pass

        self.assertNotIsSubclass(object, Protocol)
        self.assertNotIsInstance(object(), Protocol)

        self.assertNotIsSubclass(str, Protocol)
        self.assertNotIsInstance('foo', Protocol)

        self.assertNotIsSubclass(C, Protocol)
        self.assertNotIsInstance(C(), Protocol)

        only_classes_allowed = r"issubclass\(\) arg 1 must be a class"

        with self.assertRaisesRegex(TypeError, only_classes_allowed):
            issubclass(1, Protocol)
        with self.assertRaisesRegex(TypeError, only_classes_allowed):
            issubclass('foo', Protocol)
        with self.assertRaisesRegex(TypeError, only_classes_allowed):
            issubclass(C(), Protocol)

        T = TypeVar('T')

        @runtime_checkable
        class EmptyProtocol(Protocol): pass

        @runtime_checkable
        class SupportsStartsWith(Protocol):
            def startswith(self, x: str) -> bool: ...

        @runtime_checkable
        class SupportsX(Protocol[T]):
            def x(self): ...

        for proto in EmptyProtocol, SupportsStartsWith, SupportsX:
            with self.subTest(proto=proto.__name__):
                self.assertIsSubclass(proto, Protocol)

        # gh-105237 / PR #105239:
        # check that the presence of Protocol subclasses
        # where `issubclass(X, <subclass>)` evaluates to True
        # doesn't influence the result of `issubclass(X, Protocol)`

>       self.assertIsSubclass(object, EmptyProtocol)

src/test_typing_extensions.py:2454:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_issubclass_and_isinstance_on_Protocol_itself.<locals>.EmptyProtocol'>, other = <class 'object'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'EmptyProtocol' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
_______________________________________________________________________ ProtocolTests.test_issubclass_fails_correctly _______________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_issubclass_fails_correctly>

    @skip_if_py312b1
    def test_issubclass_fails_correctly(self):
        @runtime_checkable
        class NonCallableMembers(Protocol):
            x = 1

        class NotRuntimeCheckable(Protocol):
            def callable_member(self) -> int: ...

        @runtime_checkable
        class RuntimeCheckable(Protocol):
            def callable_member(self) -> int: ...

        class C: pass

        # These three all exercise different code paths,
        # but should result in the same error message:
        for protocol in NonCallableMembers, NotRuntimeCheckable, RuntimeCheckable:
            with self.subTest(proto_name=protocol.__name__):
                with self.assertRaisesRegex(
                    TypeError, r"issubclass\(\) arg 1 must be a class"
                ):
>                   issubclass(C(), protocol)

src/test_typing_extensions.py:3134:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'NonCallableMembers' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
___________________________________________________________ ProtocolTests.test_no_weird_caching_with_issubclass_after_isinstance ____________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_no_weird_caching_with_issubclass_after_isinstance>

    def test_no_weird_caching_with_issubclass_after_isinstance(self):
        @runtime_checkable
        class Spam(Protocol):
            x: int

        class Eggs:
            def __init__(self) -> None:
                self.x = 42

        self.assertIsInstance(Eggs(), Spam)

        # gh-104555: If we didn't override ABCMeta.__subclasscheck__ in _ProtocolMeta,
        # TypeError wouldn't be raised here,
        # as the cached result of the isinstance() check immediately above
        # would mean the issubclass() call would short-circuit
        # before we got to the "raise TypeError" line
        with self.assertRaisesRegex(
            TypeError,
            "Protocols with non-method members don't support issubclass()"
        ):
>           issubclass(Eggs, Spam)

src/test_typing_extensions.py:2538:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'Spam' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
__________________________________________________________ ProtocolTests.test_no_weird_caching_with_issubclass_after_isinstance_2 ___________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_no_weird_caching_with_issubclass_after_isinstance_2>

    def test_no_weird_caching_with_issubclass_after_isinstance_2(self):
        @runtime_checkable
        class Spam(Protocol):
            x: int

        class Eggs: ...

        self.assertNotIsInstance(Eggs(), Spam)

        # gh-104555: If we didn't override ABCMeta.__subclasscheck__ in _ProtocolMeta,
        # TypeError wouldn't be raised here,
        # as the cached result of the isinstance() check immediately above
        # would mean the issubclass() call would short-circuit
        # before we got to the "raise TypeError" line
        with self.assertRaisesRegex(
            TypeError,
            "Protocols with non-method members don't support issubclass()"
        ):
>           issubclass(Eggs, Spam)

src/test_typing_extensions.py:2558:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'Spam' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
__________________________________________________________ ProtocolTests.test_no_weird_caching_with_issubclass_after_isinstance_3 ___________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_no_weird_caching_with_issubclass_after_isinstance_3>

    def test_no_weird_caching_with_issubclass_after_isinstance_3(self):
        @runtime_checkable
        class Spam(Protocol):
            x: int

        class Eggs:
            def __getattr__(self, attr):
                if attr == "x":
                    return 42
                raise AttributeError(attr)

        self.assertNotIsInstance(Eggs(), Spam)

        # gh-104555: If we didn't override ABCMeta.__subclasscheck__ in _ProtocolMeta,
        # TypeError wouldn't be raised here,
        # as the cached result of the isinstance() check immediately above
        # would mean the issubclass() call would short-circuit
        # before we got to the "raise TypeError" line
        with self.assertRaisesRegex(
            TypeError,
            "Protocols with non-method members don't support issubclass()"
        ):
>           issubclass(Eggs, Spam)

src/test_typing_extensions.py:2582:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'Spam' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
________________________________________________________________________ ProtocolTests.test_non_protocol_subclasses _________________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_non_protocol_subclasses>

    def test_non_protocol_subclasses(self):
        class P(Protocol):
            x = 1
        @runtime_checkable
        class PR(Protocol):
            def meth(self): pass
        class NonP(P):
            x = 1
        class NonPR(PR): pass
        class C(metaclass=abc.ABCMeta):
            x = 1
        class D(metaclass=abc.ABCMeta):
            def meth(self): pass  # noqa: B027
        self.assertNotIsInstance(C(), NonP)
        self.assertNotIsInstance(D(), NonPR)
        self.assertNotIsSubclass(C, NonP)
        self.assertNotIsSubclass(D, NonPR)
        self.assertIsInstance(NonPR(), PR)
>       self.assertIsSubclass(NonPR, PR)

src/test_typing_extensions.py:3037:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_non_protocol_subclasses.<locals>.PR'>
other = <class 'test_typing_extensions.ProtocolTests.test_non_protocol_subclasses.<locals>.NonPR'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'PR' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
_________________________________________________________________ ProtocolTests.test_none_on_callable_blocks_implementation _________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_none_on_callable_blocks_implementation>

    def test_none_on_callable_blocks_implementation(self):
        @runtime_checkable
        class P(Protocol):
            def x(self): ...
        class A:
            def x(self): ...
        class B(A):
            x = None
        class C:
            def __init__(self):
                self.x = None
>       self.assertNotIsInstance(B(), P)

src/test_typing_extensions.py:3016:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_none_on_callable_blocks_implementation.<locals>.P'>
instance = <test_typing_extensions.ProtocolTests.test_none_on_callable_blocks_implementation.<locals>.B object at 0x7fa605b33b50>

    def __instancecheck__(cls, instance):
        # We need this method for situations where attributes are
        # assigned in __init__.
        if cls is Protocol:
            return type.__instancecheck__(cls, instance)
        if not getattr(cls, "_is_protocol", False):
            # i.e., it's a concrete subclass of a protocol
            return abc.ABCMeta.__instancecheck__(cls, instance)

        if (
            not getattr(cls, '_is_runtime_protocol', False) and
            not _allow_reckless_class_checks()
        ):
            raise TypeError("Instance and class checks can only be used with"
                            " @runtime_checkable protocols")

        if abc.ABCMeta.__instancecheck__(cls, instance):
            return True

        for attr in cls.__protocol_attrs__:
            try:
                val = inspect.getattr_static(instance, attr)
            except AttributeError:
                break
            # this attribute is set by @runtime_checkable:
>           if val is None and attr not in cls.__non_callable_proto_members__:
E           AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:651: AttributeError
____________________________________________________________ ProtocolTests.test_none_on_non_callable_doesnt_block_implementation ____________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_none_on_non_callable_doesnt_block_implementation>

    def test_none_on_non_callable_doesnt_block_implementation(self):
        @runtime_checkable
        class P(Protocol):
            x = 1
        class A:
            x = 1
        class B(A):
            x = None
        class C:
            def __init__(self):
                self.x = None
>       self.assertIsInstance(B(), P)

src/test_typing_extensions.py:3002:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_none_on_non_callable_doesnt_block_implementation.<locals>.P'>
instance = <test_typing_extensions.ProtocolTests.test_none_on_non_callable_doesnt_block_implementation.<locals>.B object at 0x7fa6058311b0>

    def __instancecheck__(cls, instance):
        # We need this method for situations where attributes are
        # assigned in __init__.
        if cls is Protocol:
            return type.__instancecheck__(cls, instance)
        if not getattr(cls, "_is_protocol", False):
            # i.e., it's a concrete subclass of a protocol
            return abc.ABCMeta.__instancecheck__(cls, instance)

        if (
            not getattr(cls, '_is_runtime_protocol', False) and
            not _allow_reckless_class_checks()
        ):
            raise TypeError("Instance and class checks can only be used with"
                            " @runtime_checkable protocols")

        if abc.ABCMeta.__instancecheck__(cls, instance):
            return True

        for attr in cls.__protocol_attrs__:
            try:
                val = inspect.getattr_static(instance, attr)
            except AttributeError:
                break
            # this attribute is set by @runtime_checkable:
>           if val is None and attr not in cls.__non_callable_proto_members__:
E           AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:651: AttributeError
_________________________________________________________________________ ProtocolTests.test_none_treated_correctly _________________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_none_treated_correctly>

    def test_none_treated_correctly(self):
        @runtime_checkable
        class P(Protocol):
            x: int = None
        class B: pass
        self.assertNotIsInstance(B(), P)
        class C:
            x = 1
        class D:
            x = None
        self.assertIsInstance(C(), P)
>       self.assertIsInstance(D(), P)

src/test_typing_extensions.py:3323:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_none_treated_correctly.<locals>.P'>
instance = <test_typing_extensions.ProtocolTests.test_none_treated_correctly.<locals>.D object at 0x7fa605840220>

    def __instancecheck__(cls, instance):
        # We need this method for situations where attributes are
        # assigned in __init__.
        if cls is Protocol:
            return type.__instancecheck__(cls, instance)
        if not getattr(cls, "_is_protocol", False):
            # i.e., it's a concrete subclass of a protocol
            return abc.ABCMeta.__instancecheck__(cls, instance)

        if (
            not getattr(cls, '_is_runtime_protocol', False) and
            not _allow_reckless_class_checks()
        ):
            raise TypeError("Instance and class checks can only be used with"
                            " @runtime_checkable protocols")

        if abc.ABCMeta.__instancecheck__(cls, instance):
            return True

        for attr in cls.__protocol_attrs__:
            try:
                val = inspect.getattr_static(instance, attr)
            except AttributeError:
                break
            # this attribute is set by @runtime_checkable:
>           if val is None and attr not in cls.__non_callable_proto_members__:
E           AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:651: AttributeError
_____________________________________________________________ ProtocolTests.test_protocol_decorated_with_final_callable_members _____________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_protocol_decorated_with_final_callable_members>

    def test_protocol_decorated_with_final_callable_members(self):
        @final
        @runtime_checkable
        class ProtocolWithMethod(Protocol):
            def startswith(self, string: str) -> bool: ...

>       self.assertIsSubclass(str, ProtocolWithMethod)

src/test_typing_extensions.py:3642:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_protocol_decorated_with_final_callable_members.<locals>.ProtocolWithMethod'>, other = <class 'str'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'ProtocolWithMethod' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
______________________________________________________________ ProtocolTests.test_protocol_decorated_with_final_mixed_members _______________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_protocol_decorated_with_final_mixed_members>

    def test_protocol_decorated_with_final_mixed_members(self):
        @final
        @runtime_checkable
        class ProtocolWithMixedMembers(Protocol):
            x: int
            def method(self) -> None: ...

        class Foo:
            x = 42
            def method(self) -> None: ...

        only_callable_members_please = (
            r"Protocols with non-method members don't support issubclass()"
        )

        with self.assertRaisesRegex(TypeError, only_callable_members_please):
>           issubclass(Foo, ProtocolWithMixedMembers)

src/test_typing_extensions.py:3685:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'ProtocolWithMixedMembers' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
___________________________________________________________ ProtocolTests.test_protocol_decorated_with_final_noncallable_members ____________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_protocol_decorated_with_final_noncallable_members>

    def test_protocol_decorated_with_final_noncallable_members(self):
        @final
        @runtime_checkable
        class ProtocolWithNonCallableMember(Protocol):
            x: int

        class Foo:
            x = 42

        only_callable_members_please = (
            r"Protocols with non-method members don't support issubclass()"
        )

        with self.assertRaisesRegex(TypeError, only_callable_members_please):
>           issubclass(Foo, ProtocolWithNonCallableMember)

src/test_typing_extensions.py:3661:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'ProtocolWithNonCallableMember' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
___________________________________________________________________ ProtocolTests.test_protocol_issubclass_error_message ____________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_protocol_issubclass_error_message>

    def test_protocol_issubclass_error_message(self):
        @runtime_checkable
        class Vec2D(Protocol):
            x: float
            y: float

            def square_norm(self) -> float:
                return self.x ** 2 + self.y ** 2

        self.assertEqual(Vec2D.__protocol_attrs__, {'x', 'y', 'square_norm'})
        expected_error_message = (
            "Protocols with non-method members don't support issubclass()."
            " Non-method members: 'x', 'y'."
        )
        with self.assertRaisesRegex(TypeError, re.escape(expected_error_message)):
>           issubclass(int, Vec2D)

src/test_typing_extensions.py:3708:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'Vec2D' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
__________________________________________________________________________ ProtocolTests.test_protocols_issubclass __________________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_protocols_issubclass>

    def test_protocols_issubclass(self):
        T = TypeVar('T')
        @runtime_checkable
        class P(Protocol):
            def x(self): ...
        @runtime_checkable
        class PG(Protocol[T]):
            def x(self): ...
        class BadP(Protocol):
            def x(self): ...
        class BadPG(Protocol[T]):
            def x(self): ...
        class C:
            def x(self): ...
>       self.assertIsSubclass(C, P)

src/test_typing_extensions.py:2296:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_protocols_issubclass.<locals>.P'>, other = <class 'test_typing_extensions.ProtocolTests.test_protocols_issubclass.<locals>.C'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
___________________________________________________________________ ProtocolTests.test_protocols_issubclass_non_callable ____________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_protocols_issubclass_non_callable>

    def test_protocols_issubclass_non_callable(self):
        class C:
            x = 1

        @runtime_checkable
        class PNonCall(Protocol):
            x = 1

        non_callable_members_illegal = (
            "Protocols with non-method members don't support issubclass()"
        )

        with self.assertRaisesRegex(TypeError, non_callable_members_illegal):
>           issubclass(C, PNonCall)

src/test_typing_extensions.py:2496:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'PNonCall' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
_____________________________________________________________________________ ProtocolTests.test_runtime_alias ______________________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_runtime_alias>

    def test_runtime_alias(self):
>       self.assertIs(runtime, runtime_checkable)
E       AssertionError: <function runtime_checkable at 0x7fa605962ef0> is not <function runtime_checkable at 0x7fa6064ee320>

src/test_typing_extensions.py:2043: AssertionError
_______________________________________________________________________ ProtocolTests.test_runtime_checkable_generic ________________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_runtime_checkable_generic>

    def test_runtime_checkable_generic(self):
        @runtime_checkable
        class Foo(Protocol[T]):
            def meth(self) -> T: ...

        class Impl:
            def meth(self) -> int: ...

>       self.assertIsSubclass(Impl, Foo)

src/test_typing_extensions.py:2924:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_runtime_checkable_generic.<locals>.Foo'>
other = <class 'test_typing_extensions.ProtocolTests.test_runtime_checkable_generic.<locals>.Impl'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'Foo' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
__________________________________________________________ ProtocolTests.test_runtime_protocol_interaction_with_evil_classproperty __________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_runtime_protocol_interaction_with_evil_classproperty>

    def test_runtime_protocol_interaction_with_evil_classproperty(self):
        class CustomError(Exception): pass

        class classproperty:
            def __get__(self, instance, type):
                raise CustomError

>       with self.assertRaises(TypeError) as cm:
E       AssertionError: TypeError not raised

src/test_typing_extensions.py:3731: AssertionError
_________________________________________________________________________ ProtocolTests.test_subprotocols_extending _________________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_subprotocols_extending>

    def test_subprotocols_extending(self):
        class P1(Protocol):
            def meth1(self):
                pass
        @runtime_checkable
        class P2(P1, Protocol):
            def meth2(self):
                pass
        class C:
            def meth1(self):
                pass
            def meth2(self):
                pass
        class C1:
            def meth1(self):
                pass
        class C2:
            def meth2(self):
                pass
        self.assertNotIsInstance(C1(), P2)
        self.assertNotIsInstance(C2(), P2)
>       self.assertNotIsSubclass(C1, P2)

src/test_typing_extensions.py:2249:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:227: in assertNotIsSubclass
    if issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_subprotocols_extending.<locals>.P2'>, other = <class 'test_typing_extensions.ProtocolTests.test_subprotocols_extending.<locals>.C1'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'P2' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
__________________________________________________________________________ ProtocolTests.test_subprotocols_merging __________________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_subprotocols_merging>

    def test_subprotocols_merging(self):
        class P1(Protocol):
            def meth1(self):
                pass
        class P2(Protocol):
            def meth2(self):
                pass
        @runtime_checkable
        class P(P1, P2, Protocol):
            pass
        class C:
            def meth1(self):
                pass
            def meth2(self):
                pass
        class C1:
            def meth1(self):
                pass
        class C2:
            def meth2(self):
                pass
        self.assertNotIsInstance(C1(), P)
        self.assertNotIsInstance(C2(), P)
>       self.assertNotIsSubclass(C1, P)

src/test_typing_extensions.py:2277:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:227: in assertNotIsSubclass
    if issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_subprotocols_merging.<locals>.P'>, other = <class 'test_typing_extensions.ProtocolTests.test_subprotocols_merging.<locals>.C1'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
__________________________________________________________________ ProtocolTests.test_typing_extensions_protocol_allowlist __________________________________________________________________

self = <test_typing_extensions.ProtocolTests testMethod=test_typing_extensions_protocol_allowlist>

    @skip_if_py312b1
    def test_typing_extensions_protocol_allowlist(self):
        @runtime_checkable
        class ReleasableBuffer(Buffer, Protocol):
            def __release_buffer__(self, mv: memoryview) -> None: ...

        class C: pass
        class D:
            def __buffer__(self, flags: int) -> memoryview:
                return memoryview(b'')
            def __release_buffer__(self, mv: memoryview) -> None:
                pass

>       self.assertIsSubclass(D, ReleasableBuffer)

src/test_typing_extensions.py:3424:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/test_typing_extensions.py:220: in assertIsSubclass
    if not issubclass(cls, class_or_tuple):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_typing_extensions.ProtocolTests.test_typing_extensions_protocol_allowlist.<locals>.ReleasableBuffer'>
other = <class 'test_typing_extensions.ProtocolTests.test_typing_extensions_protocol_allowlist.<locals>.D'>

    def __subclasscheck__(cls, other):
        if cls is Protocol:
            return type.__subclasscheck__(cls, other)
        if (
            getattr(cls, '_is_protocol', False)
            and not _allow_reckless_class_checks()
        ):
            if not getattr(cls, '_is_runtime_protocol', False):
                _type_check_issubclass_arg_1(other)
                raise TypeError(
                    "Instance and class checks can only be used with "
                    "@runtime_checkable protocols"
                )
            if (
                # this attribute is set by @runtime_checkable:
>               cls.__non_callable_proto_members__
                and cls.__dict__.get("__subclasshook__") is _proto_hook
            ):
E           AttributeError: type object 'ReleasableBuffer' has no attribute '__non_callable_proto_members__'

src/typing_extensions.py:615: AttributeError
________________________________________________________________________ TypedDictTests.test_backwards_compatibility ________________________________________________________________________

self = <test_typing_extensions.TypedDictTests testMethod=test_backwards_compatibility>

    @skipIf(
        TYPING_3_13_0,
        "The keyword argument alternative to define a "
        "TypedDict type using the functional syntax is no longer supported"
    )
    def test_backwards_compatibility(self):
>       with self.assertWarns(DeprecationWarning):
E       AssertionError: DeprecationWarning not triggered

src/test_typing_extensions.py:4591: AssertionError
________________________________________________________________________ TypedDictTests.test_basics_keywords_syntax _________________________________________________________________________

self = <test_typing_extensions.TypedDictTests testMethod=test_basics_keywords_syntax>

    @skipIf(sys.version_info >= (3, 13), "3.13 removes support for kwargs")
    def test_basics_keywords_syntax(self):
>       with self.assertWarns(DeprecationWarning):
E       AssertionError: DeprecationWarning not triggered

src/test_typing_extensions.py:3794: AssertionError
____________________________________________________________________ TypedDictTests.test_typeddict_special_keyword_names ____________________________________________________________________

self = <test_typing_extensions.TypedDictTests testMethod=test_typeddict_special_keyword_names>

    @skipIf(sys.version_info >= (3, 13), "3.13 removes support for kwargs")
    def test_typeddict_special_keyword_names(self):
>       with self.assertWarns(DeprecationWarning):
E       AssertionError: DeprecationWarning not triggered

src/test_typing_extensions.py:3813: AssertionError
================================================================================== short test summary info ==================================================================================
SKIPPED [1] src/test_typing_extensions.py:3381: needs collections.abc.Buffer to exist
SKIPPED [1] src/test_typing_extensions.py:3787: Change in behavior in 3.13
SKIPPED [1] src/test_typing_extensions.py:4177: PEP 695 required
SKIPPED [1] src/test_typing_extensions.py:4688: Waiting for bpo-46491 bugfix.
SKIPPED [1] src/test_typing_extensions.py:6020: Test isn't relevant to 3.9+
SKIPPED [1] src/test_typing_extensions.py:6159: tests are only relevant to <=3.8
SKIPPED [1] src/test_typing_extensions.py:6244: __set_name__ behaviour changed on py312+ to use BaseException.add_note()
SKIPPED [1] src/test_typing_extensions.py:6648: Not yet backported for older versions of Python
SKIPPED [1] src/test_typing_extensions.py:6622: Not yet backported for older versions of Python
SKIPPED [1] src/test_typing_extensions.py:6634: Not yet backported for older versions of Python
SKIPPED [1] src/test_typing_extensions.py:6522: Not yet backported for older versions of Python
SKIPPED [1] src/test_typing_extensions.py:6509: Not yet backported for older versions of Python
FAILED src/test_typing_extensions.py::ProtocolTests::test_basic_protocol - AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_collections_protocols_allowed - AttributeError: type object 'Custom' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_custom_subclasshook_2 - AttributeError: type object 'HasX' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_defining_generic_protocols - AttributeError: type object 'PR' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_defining_generic_protocols_old_style - AttributeError: type object 'PR' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_empty_protocol_decorated_with_final - AttributeError: type object 'EmptyProtocol' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_everything_implements_empty_protocol - AttributeError: type object 'Empty' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_implicit_issubclass_between_two_protocols - AttributeError: type object 'CallableMembersProto' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_issubclass_and_isinstance_on_Protocol_itself - AttributeError: type object 'EmptyProtocol' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_issubclass_fails_correctly - AttributeError: type object 'NonCallableMembers' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_no_weird_caching_with_issubclass_after_isinstance - AttributeError: type object 'Spam' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_no_weird_caching_with_issubclass_after_isinstance_2 - AttributeError: type object 'Spam' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_no_weird_caching_with_issubclass_after_isinstance_3 - AttributeError: type object 'Spam' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_non_protocol_subclasses - AttributeError: type object 'PR' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_none_on_callable_blocks_implementation - AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_none_on_non_callable_doesnt_block_implementation - AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_none_treated_correctly - AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_protocol_decorated_with_final_callable_members - AttributeError: type object 'ProtocolWithMethod' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_protocol_decorated_with_final_mixed_members - AttributeError: type object 'ProtocolWithMixedMembers' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_protocol_decorated_with_final_noncallable_members - AttributeError: type object 'ProtocolWithNonCallableMember' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_protocol_issubclass_error_message - AttributeError: type object 'Vec2D' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_protocols_issubclass - AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_protocols_issubclass_non_callable - AttributeError: type object 'PNonCall' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_runtime_alias - AssertionError: <function runtime_checkable at 0x7fa605962ef0> is not <function runtime_checkable at 0x7fa6064ee320>
FAILED src/test_typing_extensions.py::ProtocolTests::test_runtime_checkable_generic - AttributeError: type object 'Foo' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_runtime_protocol_interaction_with_evil_classproperty - AssertionError: TypeError not raised
FAILED src/test_typing_extensions.py::ProtocolTests::test_subprotocols_extending - AttributeError: type object 'P2' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_subprotocols_merging - AttributeError: type object 'P' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::ProtocolTests::test_typing_extensions_protocol_allowlist - AttributeError: type object 'ReleasableBuffer' has no attribute '__non_callable_proto_members__'
FAILED src/test_typing_extensions.py::TypedDictTests::test_backwards_compatibility - AssertionError: DeprecationWarning not triggered
FAILED src/test_typing_extensions.py::TypedDictTests::test_basics_keywords_syntax - AssertionError: DeprecationWarning not triggered
FAILED src/test_typing_extensions.py::TypedDictTests::test_typeddict_special_keyword_names - AssertionError: DeprecationWarning not triggered
======================================================================== 32 failed, 390 passed, 12 skipped in 8.40s =========================================================================

BTW ..

SKIPPED [1] src/test_typing_extensions.py:6159: tests are only relevant to <=3.8

I think that this unit could be removed.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jun 2, 2024

I don't think the pyupgrade patch is appropriate, since e.g. it's changing tests for the functional TypedDict calls / checking for DeprecationWarnings. The errors for __non_callable_proto_members__ are because it's now using the wrong imports

@hauntsaninja
Copy link
Collaborator

Yeah, I don't think the changes here are useful. typing_extensions and its tests are somewhat special :-)

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2024
@kloczek
Copy link
Author

kloczek commented Jun 2, 2024

So you don't see any possibility to adjust typing-extensions code or pyuprade filtering? 🤔

If may I ask you to have look on results of pypgrade --py3{9,10,11,12}-plus .. maybe it is something what could be done 😋

@kloczek
Copy link
Author

kloczek commented Jun 2, 2024

What about remove unit src/test_typing_extensions.py:6159? This seems make sense to remove? 🤔

@AlexWaygood
Copy link
Member

AlexWaygood commented Jun 2, 2024

We already have several of Ruff's pyupgrade rules enabled on this repo, but we deliberately disable most of the typing-related ones. It's pretty important that e.g. we import everything from typing_extensions rather than typing in our test suite, or we might end up testing the version of the symbol from typing.py rather than the version of the symbol that we reimplement in this repo.

Thanks for the suggestion, but there's nothing to do here.

What about remove unit src/test_typing_extensions.py:6159? This seems make sense to remove? 🤔

Why? We still support Python 3.8. The test is only skipped if you run the test using Python 3.9 or higher. We run tests with Python 3.8-3.13 inclusive in CI.

@AlexWaygood
Copy link
Member

The test failures do reveal a bug in pyupgrade, however. It correctly isn't upgrading Protocol to be imported from typing, but it's upgrading runtime_checkable all the same. Using typing.runtime_checkable with typing_extensions.Protocol won't work these days, so if it's leaving one untouched, it should leave the other untouched as well.

The fix is to make a PR like asottile/reorder-python-imports#341 that adjusts the imports that pyupgrade rewrites. Ruff probably needs a similar PR as well.

@kloczek
Copy link
Author

kloczek commented Jun 2, 2024

OK good to know 👍

@AlexWaygood
Copy link
Member

I filed asottile/reorder-python-imports#380 and astral-sh/ruff#11693.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants