mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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>
This commit is contained in:
parent
014c7f9047
commit
71af090e24
3 changed files with 38 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue