Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ jobs:
fail-fast: false
matrix:
python: [
"3.8",
"3.9",
"3.10",
"3.11",
"3.12",
"3.13",
"3.14",
"3.15",
]

steps:
Expand Down
15 changes: 13 additions & 2 deletions mypy_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def _typeddict_new(cls, _typename, _fields=None, **kwargs):
return _TypedDictMeta(_typename, (), ns, _from_functional_call=True)


def _get_own_annotations(tp):
if sys.version_info >= (3, 14):
import annotationlib
return annotationlib.get_annotations(tp)
return tp.__dict__.get('__annotations__', {})


class _TypedDictMeta(type):
def __new__(cls, name, bases, ns, total=True, _from_functional_call=False):
# Create new typed dict class object.
Expand All @@ -71,11 +78,15 @@ def __new__(cls, name, bases, ns, total=True, _from_functional_call=False):
ns['__new__'] = _typeddict_new if name == 'TypedDict' else _dict_new
tp_dict = super(_TypedDictMeta, cls).__new__(cls, name, (dict,), ns)

anns = ns.get('__annotations__', {})
if '__annotations__' in ns:
anns = ns['__annotations__']
else:
# Python 3.14+ evaluates class annotations lazily (PEP 649)
anns = _get_own_annotations(tp_dict)
msg = "TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a type"
anns = {n: _type_check(tp, msg) for n, tp in anns.items()}
for base in bases:
anns.update(base.__dict__.get('__annotations__', {}))
anns.update(_get_own_annotations(base))
tp_dict.__annotations__ = anns
if not hasattr(tp_dict, '__total__'):
tp_dict.__total__ = total
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ classifiers = [
"Environment :: Console",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15",
"Topic :: Software Development",
]
requires-python = ">=3.8"
requires-python = ">=3.10"

[project.urls]
Homepage = "https://github.com/python/mypy_extensions"
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
minversion = 4.4.4
skip_missing_interpreters = true
envlist = py38, py39, py310, py311, py312, py313
envlist = py310, py311, py312, py313, py314, py315

[testenv]
description = run the test driver with {basepython}
Expand Down
Loading