diff options
author | Felix Scherz <felixwscherz@gmail.com> | 2025-04-16 15:20:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-16 15:20:35 (GMT) |
commit | 71af090e24f4df7557e4ad77f26bf0219ef672be (patch) | |
tree | c18613c265910f1688a051d5501796806cea593e /Lib/test/test_typing.py | |
parent | 014c7f90478780b18d0e33d456483178c8dcc665 (diff) | |
download | cpython-71af090e24f4df7557e4ad77f26bf0219ef672be.zip cpython-71af090e24f4df7557e4ad77f26bf0219ef672be.tar.gz cpython-71af090e24f4df7557e4ad77f26bf0219ef672be.tar.bz2 |
gh-132493: lazy evaluation of annotations in `typing._proto_hook` (#132534)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r-- | Lib/test/test_typing.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 16c5a52..5b05ebe 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -4554,6 +4554,33 @@ class ProtocolTests(BaseTestCase): ) self.assertIs(type(exc.__cause__), CustomError) + def test_isinstance_with_deferred_evaluation_of_annotations(self): + @runtime_checkable + class P(Protocol): + def meth(self): + ... + + class DeferredClass: + x: undefined + + class DeferredClassImplementingP: + x: undefined | int + + def __init__(self): + self.x = 0 + + def meth(self): + ... + + # override meth with a non-method attribute to make it part of __annotations__ instead of __dict__ + class SubProtocol(P, Protocol): + meth: undefined + + + self.assertIsSubclass(SubProtocol, P) + self.assertNotIsInstance(DeferredClass(), P) + self.assertIsInstance(DeferredClassImplementingP(), P) + def test_deferred_evaluation_of_annotations(self): class DeferredProto(Protocol): x: DoesNotExist |