diff --git a/tests/__init__.py b/tests/__init__.py index f28f2c2..848184e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -57,3 +57,12 @@ class RuntimeProtocol(Protocol): member: int def meth(self, x: str) -> None: ... + + +class EmptyStaticProtocol(Protocol): + pass + + +@runtime_checkable +class EmptyRuntimeProtocol(Protocol): + pass diff --git a/tests/test_checkers.py b/tests/test_checkers.py index d9237a9..dc60e03 100644 --- a/tests/test_checkers.py +++ b/tests/test_checkers.py @@ -52,6 +52,8 @@ from . import ( Child, Employee, + EmptyRuntimeProtocol, + EmptyStaticProtocol, JSONType, Parent, RuntimeProtocol, @@ -1193,6 +1195,22 @@ def meth(self, x: str, y: int) -> None: ) +@pytest.mark.parametrize( + "instantiate, annotation", + [ + pytest.param(True, EmptyRuntimeProtocol, id="instance_runtime"), + pytest.param(False, Type[EmptyRuntimeProtocol], id="class_runtime"), + pytest.param(True, EmptyStaticProtocol, id="instance_static"), + pytest.param(False, Type[EmptyStaticProtocol], id="class_static"), + ], +) +@pytest.mark.parametrize("instance_type", [object, str, Parent]) +class TestEmptyProtocol: + def test_empty_protocol(self, instantiate, annotation, instance_type): + subject = instance_type() if instantiate else instance_type + check_type(subject, annotation) + + class TestRecursiveType: def test_valid(self): check_type({"a": [1, 2, 3]}, JSONType)