diff --git a/mypy-requirements.txt b/mypy-requirements.txt index 7043765f09f4..ba6f069661ad 100644 --- a/mypy-requirements.txt +++ b/mypy-requirements.txt @@ -1,5 +1,6 @@ # NOTE: this needs to be kept in sync with the "requires" list in pyproject.toml -typing_extensions>=4.1.0 +typing_extensions>=4.1.0; python_version >= '3.8' +typing_extensions>=4.7.0; python_version < '3.8' mypy_extensions>=1.0.0 typed_ast>=1.4.0,<2; python_version<'3.8' tomli>=1.1.0; python_version<'3.11' diff --git a/mypyc/irbuild/classdef.py b/mypyc/irbuild/classdef.py index fcb2afba0939..ef8db97c818e 100644 --- a/mypyc/irbuild/classdef.py +++ b/mypyc/irbuild/classdef.py @@ -2,6 +2,7 @@ from __future__ import annotations +import typing_extensions from abc import abstractmethod from typing import Callable from typing_extensions import Final @@ -498,9 +499,14 @@ def populate_non_ext_bases(builder: IRBuilder, cdef: ClassDef) -> Value: if builder.options.capi_version < (3, 8): # TypedDict was added to typing in Python 3.8. module = "typing_extensions" - # It needs to be "_TypedDict" on typing_extensions 4.7.0+ - # and "TypedDict" otherwise. + # TypedDict is not a real type on typing_extensions 4.7.0+ name = "_TypedDict" + if isinstance(typing_extensions.TypedDict, type): + raise RuntimeError( + "It looks like you may have an old version " + "of typing_extensions installed. " + "typing_extensions>=4.7.0 is required on Python 3.7." + ) else: # In Python 3.9 TypedDict is not a real type. name = "_TypedDict" diff --git a/pyproject.toml b/pyproject.toml index 0b14dd419d08..96a05d545946 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,8 @@ requires = [ "setuptools >= 40.6.2", "wheel >= 0.30.0", # the following is from mypy-requirements.txt - "typing_extensions>=4.1.0", + "typing_extensions>=4.1.0; python_version >= '3.8'", + "typing_extensions>=4.7.0; python_version < '3.8'", "mypy_extensions>=1.0.0", "typed_ast>=1.4.0,<2; python_version<'3.8'", "tomli>=1.1.0; python_version<'3.11'", diff --git a/setup.py b/setup.py index 81494a5566e8..85d412540013 100644 --- a/setup.py +++ b/setup.py @@ -222,7 +222,8 @@ def run(self): # When changing this, also update mypy-requirements.txt. install_requires=[ "typed_ast >= 1.4.0, < 2; python_version<'3.8'", - "typing_extensions>=4.1.0", + "typing_extensions>=4.1.0; python_version >= '3.8'", + "typing_extensions>=4.7.0; python_version < '3.8'", "mypy_extensions >= 1.0.0", "tomli>=1.1.0; python_version<'3.11'", ],