mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
gh-119180: Use equality when comparing against annotationlib.Format (#131755)
This commit is contained in:
parent
8a00c9a4d2
commit
af2afd7c22
3 changed files with 7 additions and 5 deletions
|
|
@ -2315,7 +2315,7 @@ def get_type_hints(obj, globalns=None, localns=None, include_extras=False,
|
|||
hints = {}
|
||||
for base in reversed(obj.__mro__):
|
||||
ann = annotationlib.get_annotations(base, format=format)
|
||||
if format is annotationlib.Format.STRING:
|
||||
if format == annotationlib.Format.STRING:
|
||||
hints.update(ann)
|
||||
continue
|
||||
if globalns is None:
|
||||
|
|
@ -2339,7 +2339,7 @@ def get_type_hints(obj, globalns=None, localns=None, include_extras=False,
|
|||
value = _eval_type(value, base_globals, base_locals, base.__type_params__,
|
||||
format=format, owner=obj)
|
||||
hints[name] = value
|
||||
if include_extras or format is annotationlib.Format.STRING:
|
||||
if include_extras or format == annotationlib.Format.STRING:
|
||||
return hints
|
||||
else:
|
||||
return {k: _strip_annotations(t) for k, t in hints.items()}
|
||||
|
|
@ -2353,7 +2353,7 @@ def get_type_hints(obj, globalns=None, localns=None, include_extras=False,
|
|||
and not hasattr(obj, '__annotate__')
|
||||
):
|
||||
raise TypeError(f"{obj!r} is not a module, class, or callable.")
|
||||
if format is annotationlib.Format.STRING:
|
||||
if format == annotationlib.Format.STRING:
|
||||
return hints
|
||||
|
||||
if globalns is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue