Skip to content

Fix tests on Python 3.14 #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix lint
  • Loading branch information
JelleZijlstra committed May 5, 2025
commit 83ff33aad4e53ecbd026bfdd683b3c460708e045
10 changes: 5 additions & 5 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5176,7 +5176,7 @@ class Y(TypedDict):
def test_delayed_type_check(self):
# _type_check is also applied later
class Z(TypedDict):
a: undefined
a: undefined # noqa: F821

with self.assertRaises(NameError):
Z.__annotations__
Expand All @@ -5185,15 +5185,15 @@ class Z(TypedDict):
with self.assertRaisesRegex(TypeError, "Plain typing.Final is not valid as type argument"):
Z.__annotations__

undefined = None
undefined = None # noqa: F841
self.assertEqual(Z.__annotations__, {'a': type(None)})

@skipUnless(TYPING_3_14_0, "Only supported on 3.14")
def test_deferred_evaluation(self):
class A(TypedDict):
x: NotRequired[undefined]
y: ReadOnly[undefined]
z: Required[undefined]
x: NotRequired[undefined] # noqa: F821
y: ReadOnly[undefined] # noqa: F821
z: Required[undefined] # noqa: F821

self.assertEqual(A.__required_keys__, frozenset({'y', 'z'}))
self.assertEqual(A.__optional_keys__, frozenset({'x'}))
Expand Down
14 changes: 9 additions & 5 deletions src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,10 +1025,14 @@ def __new__(cls, name, bases, ns, *, total=True, closed=None,
if "__annotations__" in ns:
own_annotations = ns["__annotations__"]
elif sys.version_info >= (3, 14):
own_annotate = annotationlib.get_annotate_from_class_namespace(ns)
if hasattr(annotationlib, "get_annotate_from_class_namespace"):
own_annotate = annotationlib.get_annotate_from_class_namespace(ns)
else:
# 3.14.0a7 and earlier
own_annotate = ns.get("__annotate__")
if own_annotate is not None:
own_annotations = annotationlib.call_annotate_function(
own_annotate, annotationlib.Format.FORWARDREF, owner=tp_dict
own_annotate, Format.FORWARDREF, owner=tp_dict
)
else:
own_annotations = {}
Expand Down Expand Up @@ -1114,14 +1118,14 @@ def __annotate__(format):
if own_annotate is not None:
own = annotationlib.call_annotate_function(
own_annotate, format, owner=tp_dict)
if format != annotationlib.Format.STRING:
if format != Format.STRING:
own = {
n: typing._type_check(tp, msg, module=tp_dict.__module__)
for n, tp in own.items()
}
elif format == annotationlib.Format.STRING:
elif format == Format.STRING:
own = annotationlib.annotations_to_string(own_annotations)
elif format in (annotationlib.Format.FORWARDREF, annotationlib.Format.VALUE):
elif format in (Format.FORWARDREF, Format.VALUE):
own = own_checked_annotations
else:
raise NotImplementedError(format)
Expand Down