From ea564591608bd7b33b19c98c5e4782e902212e4c Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 29 Jun 2023 13:58:05 +0100 Subject: [PATCH 1/2] Restore compatibility with typing_extensions <4.7.0 --- mypyc/irbuild/classdef.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mypyc/irbuild/classdef.py b/mypyc/irbuild/classdef.py index fcb2afba0939..836c9a0e68d3 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,9 @@ 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. - name = "_TypedDict" + # TypedDict is not a real type on typing_extensions 4.7.0+ + if not isinstance(typing_extensions.TypedDict, type): + name = "_TypedDict" else: # In Python 3.9 TypedDict is not a real type. name = "_TypedDict" From f12d3e9e117e97464dfd7ea92d09f291aff39662 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Fri, 30 Jun 2023 11:01:33 +0100 Subject: [PATCH 2/2] Better fix, perhaps --- mypy-requirements.txt | 3 ++- mypyc/irbuild/classdef.py | 9 +++++++-- pyproject.toml | 3 ++- setup.py | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) 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 836c9a0e68d3..ef8db97c818e 100644 --- a/mypyc/irbuild/classdef.py +++ b/mypyc/irbuild/classdef.py @@ -500,8 +500,13 @@ def populate_non_ext_bases(builder: IRBuilder, cdef: ClassDef) -> Value: # TypedDict was added to typing in Python 3.8. module = "typing_extensions" # TypedDict is not a real type on typing_extensions 4.7.0+ - if not isinstance(typing_extensions.TypedDict, type): - name = "_TypedDict" + 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 22e28f8f6f68..1a24d7a8b319 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'", ],