foo.__annotations__ = {"a": "foo", "b": "str"}
for format in Format:
- if format is Format.VALUE_WITH_FAKE_GLOBALS:
+ if format == Format.VALUE_WITH_FAKE_GLOBALS:
continue
with self.subTest(format=format):
self.assertEqual(
wa = WeirdAnnotations()
for format in Format:
- if format is Format.VALUE_WITH_FAKE_GLOBALS:
+ if format == Format.VALUE_WITH_FAKE_GLOBALS:
continue
with (
self.subTest(format=format),
self.assertEqual(get_type_hints(C, format=annotationlib.Format.STRING),
{'x': 'undefined'})
+ # Make sure using an int as format also works:
+ self.assertEqual(get_type_hints(C, format=4), {'x': 'undefined'})
def test_get_type_hints_format_function(self):
def func(x: undefined) -> undefined: ...
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:
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()}
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: