Skip to content

Commit d59658d

Browse files
committed
pythongh-119180: Use equality when comparing against annotationlib.Format
1 parent 898e6b3 commit d59658d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Lib/test/test_annotationlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def foo(a: int, b: str):
517517

518518
foo.__annotations__ = {"a": "foo", "b": "str"}
519519
for format in Format:
520-
if format is Format.VALUE_WITH_FAKE_GLOBALS:
520+
if format == Format.VALUE_WITH_FAKE_GLOBALS:
521521
continue
522522
with self.subTest(format=format):
523523
self.assertEqual(
@@ -816,7 +816,7 @@ def __annotations__(self):
816816

817817
wa = WeirdAnnotations()
818818
for format in Format:
819-
if format is Format.VALUE_WITH_FAKE_GLOBALS:
819+
if format == Format.VALUE_WITH_FAKE_GLOBALS:
820820
continue
821821
with (
822822
self.subTest(format=format),

Lib/typing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,7 +2315,7 @@ def get_type_hints(obj, globalns=None, localns=None, include_extras=False,
23152315
hints = {}
23162316
for base in reversed(obj.__mro__):
23172317
ann = annotationlib.get_annotations(base, format=format)
2318-
if format is annotationlib.Format.STRING:
2318+
if format == annotationlib.Format.STRING:
23192319
hints.update(ann)
23202320
continue
23212321
if globalns is None:
@@ -2339,7 +2339,7 @@ def get_type_hints(obj, globalns=None, localns=None, include_extras=False,
23392339
value = _eval_type(value, base_globals, base_locals, base.__type_params__,
23402340
format=format, owner=obj)
23412341
hints[name] = value
2342-
if include_extras or format is annotationlib.Format.STRING:
2342+
if include_extras or format == annotationlib.Format.STRING:
23432343
return hints
23442344
else:
23452345
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,
23532353
and not hasattr(obj, '__annotate__')
23542354
):
23552355
raise TypeError(f"{obj!r} is not a module, class, or callable.")
2356-
if format is annotationlib.Format.STRING:
2356+
if format == annotationlib.Format.STRING:
23572357
return hints
23582358

23592359
if globalns is None:

0 commit comments

Comments
 (0)