diff options
author | Tomas R <tomas.roun8@gmail.com> | 2023-05-25 20:14:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-25 20:14:58 (GMT) |
commit | fea8632ec69d160a11b8ec506900c14989952bc1 (patch) | |
tree | 856e592194ea9a7e46f98767999d2697c0534d3f /Lib | |
parent | d08679212d9af52dd074cd4a6abb440edb944c9c (diff) | |
download | cpython-fea8632ec69d160a11b8ec506900c14989952bc1.zip cpython-fea8632ec69d160a11b8ec506900c14989952bc1.tar.gz cpython-fea8632ec69d160a11b8ec506900c14989952bc1.tar.bz2 |
gh-104786: Remove kwargs-based TypedDict creation (#104891)
Deprecated since Python 3.11.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_typing.py | 33 | ||||
-rw-r--r-- | Lib/typing.py | 19 |
2 files changed, 5 insertions, 47 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index d328b0e..57a2926 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -7018,35 +7018,6 @@ class TypedDictTests(BaseTestCase): self.assertEqual(Emp.__annotations__, {'name': str, 'id': int}) self.assertEqual(Emp.__total__, True) - def test_basics_keywords_syntax(self): - with self.assertWarns(DeprecationWarning): - Emp = TypedDict('Emp', name=str, id=int) - self.assertIsSubclass(Emp, dict) - self.assertIsSubclass(Emp, typing.MutableMapping) - self.assertNotIsSubclass(Emp, collections.abc.Sequence) - jim = Emp(name='Jim', id=1) - self.assertIs(type(jim), dict) - self.assertEqual(jim['name'], 'Jim') - self.assertEqual(jim['id'], 1) - self.assertEqual(Emp.__name__, 'Emp') - self.assertEqual(Emp.__module__, __name__) - self.assertEqual(Emp.__bases__, (dict,)) - self.assertEqual(Emp.__annotations__, {'name': str, 'id': int}) - self.assertEqual(Emp.__total__, True) - - def test_typeddict_special_keyword_names(self): - with self.assertWarns(DeprecationWarning): - TD = TypedDict("TD", cls=type, self=object, typename=str, _typename=int, fields=list, _fields=dict) - self.assertEqual(TD.__name__, 'TD') - self.assertEqual(TD.__annotations__, {'cls': type, 'self': object, 'typename': str, '_typename': int, 'fields': list, '_fields': dict}) - a = TD(cls=str, self=42, typename='foo', _typename=53, fields=[('bar', tuple)], _fields={'baz', set}) - self.assertEqual(a['cls'], str) - self.assertEqual(a['self'], 42) - self.assertEqual(a['typename'], 'foo') - self.assertEqual(a['_typename'], 53) - self.assertEqual(a['fields'], [('bar', tuple)]) - self.assertEqual(a['_fields'], {'baz', set}) - def test_typeddict_create_errors(self): with self.assertRaises(TypeError): TypedDict.__new__() @@ -7055,7 +7026,9 @@ class TypedDictTests(BaseTestCase): with self.assertRaises(TypeError): TypedDict('Emp', [('name', str)], None) with self.assertRaises(TypeError): - TypedDict(_typename='Emp', name=str, id=int) + TypedDict(_typename='Emp') + with self.assertRaises(TypeError): + TypedDict('Emp', name=str, id=int) def test_typeddict_errors(self): Emp = TypedDict('Emp', {'name': str, 'id': int}) diff --git a/Lib/typing.py b/Lib/typing.py index 85d129b..13f0883 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -29,7 +29,6 @@ import operator import re as stdlib_re # Avoid confusion with the typing.re namespace on <=3.11 import sys import types -import warnings from types import WrapperDescriptorType, MethodWrapperType, MethodDescriptorType, GenericAlias from _typing import ( @@ -2822,7 +2821,7 @@ class _TypedDictMeta(type): __instancecheck__ = __subclasscheck__ -def TypedDict(typename, fields=None, /, *, total=True, **kwargs): +def TypedDict(typename, fields=None, /, *, total=True): """A simple typed namespace. At runtime it is equivalent to a plain dict. TypedDict creates a dictionary type that expects all of its @@ -2859,23 +2858,9 @@ def TypedDict(typename, fields=None, /, *, total=True, **kwargs): checker is only expected to support a literal False or True as the value of the total argument. True is the default, and makes all items defined in the class body be required. - - The class syntax is only supported in Python 3.6+, while the other - syntax form works for Python 2.7 and 3.2+ """ if fields is None: - fields = kwargs - elif kwargs: - raise TypeError("TypedDict takes either a dict or keyword arguments," - " but not both") - if kwargs: - warnings.warn( - "The kwargs-based syntax for TypedDict definitions is deprecated " - "in Python 3.11, will be removed in Python 3.13, and may not be " - "understood by third-party type checkers.", - DeprecationWarning, - stacklevel=2, - ) + fields = {} ns = {'__annotations__': dict(fields)} module = _caller() |