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/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/typing.py')
-rw-r--r-- | Lib/typing.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 3678962..245592b 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -2020,10 +2020,13 @@ def _proto_hook(cls, other): break # ...or in annotations, if it is a sub-protocol. - annotations = getattr(base, '__annotations__', {}) - if (isinstance(annotations, collections.abc.Mapping) and - attr in annotations and - issubclass(other, Generic) and getattr(other, '_is_protocol', False)): + if ( + issubclass(other, Generic) + and getattr(other, "_is_protocol", False) + and attr in _lazy_annotationlib.get_annotations( + base, format=_lazy_annotationlib.Format.FORWARDREF + ) + ): break else: return NotImplemented |