From 12c871cbe9e645fe1423badd122a33a8c2480840 Mon Sep 17 00:00:00 2001 From: Nikhil Dabas Date: Wed, 11 Nov 2026 17:08:43 +0000 Subject: [PATCH 1/5] Add Python 3.14/3.15 support --- .github/workflows/tests.yml | 31 ++++++++++++------------------- pyproject.toml | 10 ++++++++-- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 66cecbb0..8cc183ec 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,28 +11,21 @@ on: jobs: tests: - runs-on: ${{ matrix.os }} + name: tests (${{ matrix.python-version }}, ${{ matrix.platform.os }}, ${{ matrix.platform.arch }}) + runs-on: ${{ matrix.platform.os }} strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] - os: [windows-latest, ubuntu-latest, macos-latest] - arch: [x64, x86] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] + platform: + - {os: windows-latest, arch: x64} + - {os: windows-latest, arch: x86} + - {os: ubuntu-latest, arch: x64} + - &macos-x64 {os: macos-latest, arch: x64} exclude: - # 32-bit Python is only available on Windows - - os: ubuntu-latest - arch: x86 - - os: macos-latest - arch: x86 # https://github.com/actions/setup-python/issues/948 - - os: macos-latest - arch: x64 - python-version: 3.8 - - os: macos-latest - arch: x64 - python-version: 3.9 - - os: macos-latest - arch: x64 - python-version: 3.10 + - {platform: *macos-x64, python-version: "3.8"} + - {platform: *macos-x64, python-version: "3.9"} + - {platform: *macos-x64, python-version: "3.10"} steps: - uses: actions/checkout@v4 @@ -57,7 +50,7 @@ jobs: PIP_DISABLE_PIP_VERSION_CHECK: 1 with: python-version: ${{ matrix.python-version }} - architecture: ${{ matrix.arch }} + architecture: ${{ matrix.platform.arch }} - name: Test if: steps.release.outputs.version == 0 diff --git a/pyproject.toml b/pyproject.toml index 3baa285d..782cc6ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,9 @@ classifiers=[ "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", "Programming Language :: Python :: Implementation :: CPython", "Operating System :: POSIX", "Operating System :: MacOS :: MacOS X", @@ -37,8 +40,11 @@ github = "https://github.com/MagicStack/immutables" # their combination breaks too often # (example breakage: https://gitlab.com/pycqa/flake8/issues/427) test = [ - 'flake8~=5.0', - 'pycodestyle~=2.9', + 'flake8~=5.0; python_version < "3.14"', + 'pycodestyle~=2.9; python_version < "3.14"', + # Older pyflakes relies on ast nodes removed in Python 3.14 + 'flake8~=7.3; python_version >= "3.14"', + 'pycodestyle~=2.14; python_version >= "3.14"', 'mypy~=1.4', 'pytest~=7.4', ] From 195d30fb6d9b327620be424de0cee73c31e54440 Mon Sep 17 00:00:00 2001 From: Nikhil Dabas Date: Wed, 11 Nov 2026 17:08:59 +0000 Subject: [PATCH 2/5] Add Windows ARM64 support --- .github/workflows/release.yml | 3 ++- .github/workflows/tests.yml | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 102c3163..3b8935a3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -81,7 +81,8 @@ jobs: { cibuildwheel --print-build-identifiers --platform linux --arch x86_64,aarch64 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \ && cibuildwheel --print-build-identifiers --platform macos --arch x86_64,arm64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-latest"}' \ - && cibuildwheel --print-build-identifiers --platform windows --arch x86,AMD64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-latest"}' + && cibuildwheel --print-build-identifiers --platform windows --arch x86,AMD64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-latest"}' \ + && cibuildwheel --print-build-identifiers --platform windows --arch ARM64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-11-arm"}' } | jq -sc ) echo "include=$MATRIX_INCLUDE" >> $GITHUB_OUTPUT diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8cc183ec..40589f4e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,11 +21,16 @@ jobs: - {os: windows-latest, arch: x86} - {os: ubuntu-latest, arch: x64} - &macos-x64 {os: macos-latest, arch: x64} + - &windows-arm64 {os: windows-11-arm, arch: arm64} exclude: # https://github.com/actions/setup-python/issues/948 - {platform: *macos-x64, python-version: "3.8"} - {platform: *macos-x64, python-version: "3.9"} - {platform: *macos-x64, python-version: "3.10"} + # CPython does not have a Windows ARM64 release before 3.11 + - {platform: *windows-arm64, python-version: "3.8"} + - {platform: *windows-arm64, python-version: "3.9"} + - {platform: *windows-arm64, python-version: "3.10"} steps: - uses: actions/checkout@v4 From 3165dfe47a3eea5f3f3d9122b6344071085198ef Mon Sep 17 00:00:00 2001 From: Nikhil Dabas Date: Wed, 11 Nov 2026 17:27:41 +0000 Subject: [PATCH 3/5] Drop Python 3.8/3.9 support --- .github/workflows/release.yml | 12 ++++++------ .github/workflows/tests.yml | 6 +----- README.rst | 2 +- immutables/_map.c | 13 ------------- immutables/_map.pyi | 10 ++-------- immutables/_protocols.py | 10 ++-------- immutables/map.py | 6 +----- pyproject.toml | 13 +++++-------- tests/conftest.py | 4 ---- tests/test_map.py | 10 +++------- tests/test_pattern_matching.py | 27 +++++++-------------------- 11 files changed, 28 insertions(+), 85 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b8935a3..1454cbed 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -74,15 +74,15 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.x" - - run: pip install cibuildwheel==2.21.3 + - run: pip install cibuildwheel==4.3.5 - id: set-matrix run: | MATRIX_INCLUDE=$( { - cibuildwheel --print-build-identifiers --platform linux --arch x86_64,aarch64 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \ - && cibuildwheel --print-build-identifiers --platform macos --arch x86_64,arm64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-latest"}' \ - && cibuildwheel --print-build-identifiers --platform windows --arch x86,AMD64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-latest"}' \ - && cibuildwheel --print-build-identifiers --platform windows --arch ARM64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-11-arm"}' + cibuildwheel --print-build-identifiers --platform linux --archs x86_64,aarch64 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \ + && cibuildwheel --print-build-identifiers --platform macos --archs x86_64,arm64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-latest"}' \ + && cibuildwheel --print-build-identifiers --platform windows --archs x86,AMD64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-latest"}' \ + && cibuildwheel --print-build-identifiers --platform windows --archs ARM64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-11-arm"}' } | jq -sc ) echo "include=$MATRIX_INCLUDE" >> $GITHUB_OUTPUT @@ -113,7 +113,7 @@ jobs: if: runner.os == 'Linux' uses: docker/setup-qemu-action@v2 - - uses: pypa/cibuildwheel@7940a4c0e76eb2030e473a5f864f291f63ee879b # v2.21.3 + - uses: pypa/cibuildwheel@f9b966cfadf4109556cadc5bb39ddb72d0ce664e # v4.3.5 with: only: ${{ matrix.only }} env: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 40589f4e..6a991a2b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: runs-on: ${{ matrix.platform.os }} strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] platform: - {os: windows-latest, arch: x64} - {os: windows-latest, arch: x86} @@ -24,12 +24,8 @@ jobs: - &windows-arm64 {os: windows-11-arm, arch: arm64} exclude: # https://github.com/actions/setup-python/issues/948 - - {platform: *macos-x64, python-version: "3.8"} - - {platform: *macos-x64, python-version: "3.9"} - {platform: *macos-x64, python-version: "3.10"} # CPython does not have a Windows ARM64 release before 3.11 - - {platform: *windows-arm64, python-version: "3.8"} - - {platform: *windows-arm64, python-version: "3.9"} - {platform: *windows-arm64, python-version: "3.10"} steps: diff --git a/README.rst b/README.rst index e14d3210..df948442 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,7 @@ copy-on-write approach (the benchmark code is available Installation ------------ -``immutables`` requires Python 3.6+ and is available on PyPI:: +``immutables`` requires Python 3.10+ and is available on PyPI:: $ pip install immutables diff --git a/immutables/_map.c b/immutables/_map.c index 256f4677..de65aaf9 100644 --- a/immutables/_map.c +++ b/immutables/_map.c @@ -3373,15 +3373,6 @@ map_reduce(MapObject *self) return tup; } -#if PY_VERSION_HEX < 0x030900A6 -static PyObject * -map_py_class_getitem(PyObject *type, PyObject *item) -{ - Py_INCREF(type); - return type; -} -#endif - static PyMethodDef Map_methods[] = { {"set", (PyCFunction)map_py_set, METH_VARARGS, NULL}, {"get", (PyCFunction)map_py_get, METH_VARARGS, NULL}, @@ -3395,11 +3386,7 @@ static PyMethodDef Map_methods[] = { {"__dump__", (PyCFunction)map_py_dump, METH_NOARGS, NULL}, { "__class_getitem__", -#if PY_VERSION_HEX < 0x030900A6 - (PyCFunction)map_py_class_getitem, -#else Py_GenericAlias, -#endif METH_O|METH_CLASS, "See PEP 585" }, diff --git a/immutables/_map.pyi b/immutables/_map.pyi index 039be94a..bb547d16 100644 --- a/immutables/_map.pyi +++ b/immutables/_map.pyi @@ -1,4 +1,4 @@ -import sys +from types import GenericAlias from typing import Any from typing import Dict from typing import Generic @@ -11,9 +11,6 @@ from typing import Type from typing import Union from typing import overload -if sys.version_info >= (3, 9): - from types import GenericAlias - from ._protocols import IterableItems from ._protocols import MapItems from ._protocols import MapKeys @@ -74,7 +71,4 @@ class Map(Mapping[KT, VT_co]): def items(self) -> MapItems[KT, VT_co]: ... # type: ignore[override] def __hash__(self) -> int: ... def __dump__(self) -> str: ... - if sys.version_info >= (3, 9): - def __class_getitem__(cls, item: Any) -> GenericAlias: ... - else: - def __class_getitem__(cls, item: Any) -> Type[Map[Any, Any]]: ... + def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/immutables/_protocols.py b/immutables/_protocols.py index 49d8ee1e..f136b797 100644 --- a/immutables/_protocols.py +++ b/immutables/_protocols.py @@ -1,22 +1,16 @@ -import sys from typing import Any from typing import Hashable from typing import Iterable from typing import Iterator from typing import NoReturn from typing import Optional +from typing import Protocol +from typing import TYPE_CHECKING from typing import Tuple from typing import TypeVar from typing import Union from typing import overload -if sys.version_info >= (3, 8): - from typing import Protocol - from typing import TYPE_CHECKING -else: - from typing_extensions import Protocol - from typing_extensions import TYPE_CHECKING - if TYPE_CHECKING: from ._map import Map diff --git a/immutables/map.py b/immutables/map.py index 46227357..a1a2f21d 100644 --- a/immutables/map.py +++ b/immutables/map.py @@ -662,11 +662,7 @@ def __dump__(self): # pragma: no cover self.__root.dump(buf, 0) return '\n'.join(buf) - if sys.version_info >= (3, 9): - __class_getitem__ = classmethod(types.GenericAlias) - else: - def __class_getitem__(cls, item): - return cls + __class_getitem__ = classmethod(types.GenericAlias) class MapMutation: diff --git a/pyproject.toml b/pyproject.toml index 782cc6ee..02777711 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "immutables" description = "Immutable Collections" authors = [{name = "MagicStack Inc", email = "hello@magic.io"}] -requires-python = '>=3.8.0' +requires-python = '>=3.10' readme = "README.rst" license = {text = "Apache License, Version 2.0"} dynamic = ["version"] @@ -15,8 +15,6 @@ classifiers=[ "License :: OSI Approved :: Apache Software License", "Intended Audience :: Developers", "Programming Language :: Python :: 3 :: Only", - "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", @@ -40,11 +38,8 @@ github = "https://github.com/MagicStack/immutables" # their combination breaks too often # (example breakage: https://gitlab.com/pycqa/flake8/issues/427) test = [ - 'flake8~=5.0; python_version < "3.14"', - 'pycodestyle~=2.9; python_version < "3.14"', - # Older pyflakes relies on ast nodes removed in Python 3.14 - 'flake8~=7.3; python_version >= "3.14"', - 'pycodestyle~=2.14; python_version >= "3.14"', + 'flake8~=7.3', + 'pycodestyle~=2.14', 'mypy~=1.4', 'pytest~=7.4', ] @@ -87,6 +82,8 @@ ignore_errors = true [tool.cibuildwheel] build-frontend = "build" test-extras = "test" +# The C extension does not declare free-threading support (Py_mod_gil) +skip = "cp3??t-*" [tool.cibuildwheel.macos] test-command = "python {project}/tests/__init__.py" diff --git a/tests/conftest.py b/tests/conftest.py index 210f55b2..9eb9e611 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,3 @@ -import sys # We need the mypy pytest plugin to do the test collection for our # typing tests. @@ -12,6 +11,3 @@ pytest_plugins = [ 'mypy.test.data', ] - -if sys.version_info < (3, 10): - collect_ignore = ["test_pattern_matching.py"] diff --git a/tests/test_map.py b/tests/test_map.py index 6cecfe90..80035e88 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -2,7 +2,6 @@ import gc import pickle import random -import sys import unittest import weakref @@ -1385,12 +1384,9 @@ def test_map_pickle(self): pickle.dumps(h.mutate()) def test_map_is_subscriptable(self): - if sys.version_info >= (3, 9): - with_args = self.Map[int, str] - self.assertIs(with_args.__origin__, self.Map) - self.assertEqual(with_args.__args__, (int, str)) - else: - self.assertIs(self.Map[int, str], self.Map) + with_args = self.Map[int, str] + self.assertIs(with_args.__origin__, self.Map) + self.assertEqual(with_args.__args__, (int, str)) def test_kwarg_named_col(self): self.assertEqual(dict(self.Map(col=0)), {"col": 0}) diff --git a/tests/test_pattern_matching.py b/tests/test_pattern_matching.py index 2594d887..a679bb8a 100644 --- a/tests/test_pattern_matching.py +++ b/tests/test_pattern_matching.py @@ -1,5 +1,3 @@ -import sys -import textwrap import unittest from immutables.map import Map as PyMap @@ -9,25 +7,14 @@ class BaseMapTest: Map = None - @unittest.skipIf( - sys.version_info < (3, 10), - "pattern matching is not supported in this Python version", - ) def test_map_can_be_matched(self): - locals_ = dict(locals()) - exec( - textwrap.dedent("""\ - match self.Map(a=1, b=2): # noqa: E999 - case {"a": 1 as matched}: - matched = matched - case _: - assert False - - self.assertEqual(matched, 1) - """), - globals(), - locals_, - ) + match self.Map(a=1, b=2): + case {"a": 1 as matched}: + pass + case _: + self.fail("Map did not match a mapping pattern") + + self.assertEqual(matched, 1) class PyMapTest(BaseMapTest, unittest.TestCase): From 3eb50da3a01366ed0ff904212c67a6d439874cdf Mon Sep 17 00:00:00 2001 From: Nikhil Dabas Date: Wed, 11 Nov 2026 17:29:41 +0000 Subject: [PATCH 4/5] Move Linux ARM64 builds to native runners --- .github/workflows/release.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1454cbed..89e9cec0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -79,7 +79,8 @@ jobs: run: | MATRIX_INCLUDE=$( { - cibuildwheel --print-build-identifiers --platform linux --archs x86_64,aarch64 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \ + cibuildwheel --print-build-identifiers --platform linux --archs x86_64 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \ + && cibuildwheel --print-build-identifiers --platform linux --archs aarch64 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-26.04-arm"}' \ && cibuildwheel --print-build-identifiers --platform macos --archs x86_64,arm64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-latest"}' \ && cibuildwheel --print-build-identifiers --platform windows --archs x86,AMD64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-latest"}' \ && cibuildwheel --print-build-identifiers --platform windows --archs ARM64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-11-arm"}' @@ -109,10 +110,6 @@ jobs: fetch-depth: 50 submodules: true - - name: Set up QEMU - if: runner.os == 'Linux' - uses: docker/setup-qemu-action@v2 - - uses: pypa/cibuildwheel@f9b966cfadf4109556cadc5bb39ddb72d0ce664e # v4.3.5 with: only: ${{ matrix.only }} @@ -145,7 +142,7 @@ jobs: id: relver run: | set -e - echo ::set-output name=version::$(cat dist/VERSION) + echo "version=$(cat dist/VERSION)" >> "$GITHUB_OUTPUT" rm dist/VERSION - name: Merge and tag the PR From 5dbef3459637cc5ab60b06e1681833278279e297 Mon Sep 17 00:00:00 2001 From: Nikhil Dabas Date: Thu, 12 Nov 2026 09:36:55 +0000 Subject: [PATCH 5/5] Update mypy to ~2.4.0 --- pyproject.toml | 2 +- tests/test-data/check-immu.test | 30 +++++++++++++++--------------- tests/test_mypy.py | 13 +++++++------ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 02777711..af1a0917 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ github = "https://github.com/MagicStack/immutables" test = [ 'flake8~=7.3', 'pycodestyle~=2.14', - 'mypy~=1.4', + 'mypy~=2.4.0', 'pytest~=7.4', ] diff --git a/tests/test-data/check-immu.test b/tests/test-data/check-immu.test index 2ee32f17..91a7b344 100644 --- a/tests/test-data/check-immu.test +++ b/tests/test-data/check-immu.test @@ -13,7 +13,7 @@ def init() -> None: thing(Map([('foo', 'bar'), ('bar', 1)])) thing(Map(Map(foo=1), bar='foo')) m = Map({1: 2}) - thing(m) # E: Argument 1 to "thing" has incompatible type "Map[int, int]"; expected "Map[str, Union[str, int]]" + thing(m) # E: Argument 1 to "thing" has incompatible type "Map[int, int]"; expected "Map[str, str | int]" def assignments() -> None: m_int__str = Map[int, str]() @@ -22,19 +22,19 @@ def assignments() -> None: m_str__int_str = Map[str, Union[int, str]]() m_int__str = m_str__str # E: Incompatible types in assignment (expression has type "Map[str, str]", variable has type "Map[int, str]") - m_int__str = m_int_str__str # E: Incompatible types in assignment (expression has type "Map[Union[int, str], str]", variable has type "Map[int, str]") - m_int__str = m_str__int_str # E: Incompatible types in assignment (expression has type "Map[str, Union[int, str]]", variable has type "Map[int, str]") + m_int__str = m_int_str__str # E: Incompatible types in assignment (expression has type "Map[int | str, str]", variable has type "Map[int, str]") + m_int__str = m_str__int_str # E: Incompatible types in assignment (expression has type "Map[str, int | str]", variable has type "Map[int, str]") m_str__str = m_int__str # E: Incompatible types in assignment (expression has type "Map[int, str]", variable has type "Map[str, str]") - m_str__str = m_int_str__str # E: Incompatible types in assignment (expression has type "Map[Union[int, str], str]", variable has type "Map[str, str]") - m_str__str = m_str__int_str # E: Incompatible types in assignment (expression has type "Map[str, Union[int, str]]", variable has type "Map[str, str]") + m_str__str = m_int_str__str # E: Incompatible types in assignment (expression has type "Map[int | str, str]", variable has type "Map[str, str]") + m_str__str = m_str__int_str # E: Incompatible types in assignment (expression has type "Map[str, int | str]", variable has type "Map[str, str]") - m_int_str__str = m_int__str # E: Incompatible types in assignment (expression has type "Map[int, str]", variable has type "Map[Union[int, str], str]") - m_int_str__str = m_str__str # E: Incompatible types in assignment (expression has type "Map[str, str]", variable has type "Map[Union[int, str], str]") - m_int_str__str = m_str__int_str # E: Incompatible types in assignment (expression has type "Map[str, Union[int, str]]", variable has type "Map[Union[int, str], str]") + m_int_str__str = m_int__str # E: Incompatible types in assignment (expression has type "Map[int, str]", variable has type "Map[int | str, str]") + m_int_str__str = m_str__str # E: Incompatible types in assignment (expression has type "Map[str, str]", variable has type "Map[int | str, str]") + m_int_str__str = m_str__int_str # E: Incompatible types in assignment (expression has type "Map[str, int | str]", variable has type "Map[int | str, str]") - m_str__int_str = m_int__str # E: Incompatible types in assignment (expression has type "Map[int, str]", variable has type "Map[str, Union[int, str]]") - m_str__int_str = m_int_str__str # E: Incompatible types in assignment (expression has type "Map[Union[int, str], str]", variable has type "Map[str, Union[int, str]]") + m_str__int_str = m_int__str # E: Incompatible types in assignment (expression has type "Map[int, str]", variable has type "Map[str, int | str]") + m_str__int_str = m_int_str__str # E: Incompatible types in assignment (expression has type "Map[int | str, str]", variable has type "Map[str, int | str]") m_str__int_str = m_str__str def update() -> None: @@ -45,19 +45,19 @@ def update() -> None: m_int__str.update({1: '2'}) m_int__str.update({1: '2'}, three='4') # E: Unexpected keyword argument "three" for "update" of "Map" - m_int__str.update({1: 2}) # E: Argument 1 to "update" of "Map" has incompatible type "Dict[int, int]"; expected "Union[IterableItems[int, str], Iterable[Tuple[int, str]]]" + m_int__str.update({1: 2}) # E: Argument 1 to "update" of "Map" has incompatible type "dict[int, int]"; expected "IterableItems[int, str] | Iterable[tuple[int, str]]" m_str__str.update({'1': '2'}) m_str__str.update({'1': '2'}, three='4') - m_str__str.update({'1': 2}) # E: Argument 1 to "update" of "Map" has incompatible type "Dict[str, int]"; expected "Union[IterableItems[str, str], Iterable[Tuple[str, str]]]" + m_str__str.update({'1': 2}) # E: Argument 1 to "update" of "Map" has incompatible type "dict[str, int]"; expected "IterableItems[str, str] | Iterable[tuple[str, str]]" m_int_str__str.update(cast(Dict[Union[int, str], str], {1: '2', '3': '4'})) m_int_str__str.update({1: '2'}, three='4') - m_int_str__str.update({'1': 2}) # E: Argument 1 to "update" of "Map" has incompatible type "Dict[str, int]"; expected "Union[IterableItems[Union[int, str], str], Iterable[Tuple[Union[int, str], str]]]" + m_int_str__str.update({'1': 2}) # E: Argument 1 to "update" of "Map" has incompatible type "dict[str, int]"; expected "IterableItems[int | str, str] | Iterable[tuple[int | str, str]]" m_str__int_str.update({'1': 2, '2': 3}) m_str__int_str.update({'1': 2, '2': 3}, four='5') - m_str__int_str.update({1: 2}) # E: Argument 1 to "update" of "Map" has incompatible type "Dict[int, int]"; expected "Union[IterableItems[str, Union[int, str]], Iterable[Tuple[str, Union[int, str]]]]" + m_str__int_str.update({1: 2}) # E: Argument 1 to "update" of "Map" has incompatible type "dict[int, int]"; expected "IterableItems[str, int | str] | Iterable[tuple[str, int | str]]" def mutate() -> None: m = Map[str, str]() @@ -70,4 +70,4 @@ def mutate() -> None: mm.set('3', '4') m2 = mm.finish() - reveal_type(m2) # N: Revealed type is "immutables._map.Map[builtins.str, builtins.str]" + reveal_type(m2) # N: Revealed type is "immutables._map.Map[str, str]" diff --git a/tests/test_mypy.py b/tests/test_mypy.py index 24d3a6bb..19295bea 100644 --- a/tests/test_mypy.py +++ b/tests/test_mypy.py @@ -1,5 +1,5 @@ import os -import sys +import re try: import mypy.test.testcmdline @@ -11,10 +11,12 @@ raise else: # I'm upset. There's no other way to deal with the little 'defined here' - # notes that mypy emits when passing an unexpected keyword argument - # and at no other time. + # (or, in newer mypy, 'defined in "module"') notes that mypy emits when + # passing an unexpected keyword argument and at no other time. + _defined_note = re.compile(r'note: .* defined (here|in "[^"]+")$') + def renormalize_error_messages(messages): - messages = [x for x in messages if not x.endswith(' defined here')] + messages = [x for x in messages if not _defined_note.search(x)] return normalize_error_messages(messages) mypy.test.testcmdline.normalize_error_messages = renormalize_error_messages @@ -34,6 +36,5 @@ class ImmuMypyTest(mypy.test.testcmdline.PythonCmdlineSuite): files = ['check-immu.test'] def run_case(self, testcase): - if sys.version_info >= (3, 7): - os.environ["MYPYPATH"] = mypy_path + os.environ["MYPYPATH"] = mypy_path super().run_case(testcase)