8000 Fix tests on Python 3.13, add note on TypedDict kwargs (#212) · python/typing_extensions@d95cc22 · GitHub
[go: up one dir, main page]

Skip to content

Commit d95cc22

Browse files
Fix tests on Python 3.13, add note on TypedDict kwargs (#212)
Fixes #204
1 parent 0f9fb78 commit d95cc22

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Unreleased
22

33
- Declare support for Python 3.12. Patch by Jelle Zijlstra.
4+
- Fix tests on Python 3.13, which removes support for creating
5+
`TypedDict` classes through the keyword-argument syntax. Patch by
6+
Jelle Zijlstra.
47

58
# Release 4.6.3 (June 1, 2023)
69

doc/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ Special typing primitives
276276
``typing_extensions`` backport provides all of these features and bugfixes on
277277
all Python versions.
278278

279+
Historically, ``TypedDict`` has supported an alternative creation syntax
280+
where the fields are supplied as keyword arguments (e.g.,
281+
``TypedDict("TD", a=int, b=str)``). In CPython, this feature was deprecated
282+
in Python 3.11 and removed in Python 3.13. ``typing_extensions.TypedDict``
283+
raises a :py:exc:`DeprecationWarning` when this syntax is used in Python 3.12
284+
or lower and fails with a :py:exc:`TypeError` in Python 3.13 and higher.
285+
279286
.. versionchanged:: 4.3.0
280287

281288
Added support for generic ``TypedDict``\ s.

src/test_typing_extensions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,12 @@ def test_basics_iterable_syntax(self):
28792879
self.assertEqual(Emp.__annotations__, {'name': str, 'id': int})
28802880
self.assertEqual(Emp.__total__, True)
28812881

2882+
@skipIf(sys.version_info < (3, 13), "Change in behavior in 3.13")
2883+
def test_keywords_syntax_raises_on_3_13(self):
2884+
with self.assertRaises(TypeError):
2885+
Emp = TypedDict('Emp', name=str, id=int)
2886+
2887+
@skipIf(sys.version_info >= (3, 13), "3.13 removes support for kwargs")
28822888
def test_basics_keywords_syntax(self):
28832889
with self.assertWarns(DeprecationWarning):
28842890
Emp = TypedDict('Emp', name=str, id=int)
@@ -2895,6 +2901,7 @@ def test_basics_keywords_syntax(self):
28952901
self.assertEqual(Emp.__annotations__, {'name': str, 'id': int})
28962902
self.assertEqual(Emp.__total__, True)
28972903

2904+
@skipIf(sys.version_info >= (3, 13), "3.13 removes support for kwargs")
28982905
def test_typeddict_special_keyword_names(self):
28992906
with self.assertWarns(DeprecationWarning):
29002907
TD = TypedDict("TD", cls=type, self=object, typename=str, _typename=int,

0 commit comments

Comments
 (0)
0