From d33f5d6445ddb7b31e12ea9cbafe28baf84e0bff Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 16 Mar 2026 20:04:39 +0000 Subject: [PATCH 1/4] Add ast-serialize as an optional dependency --- .github/workflows/test.yml | 16 ++++++++-------- pyproject.toml | 1 + test-data/unit/check-overloading.test | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b2219cc7c400..6fe36b8b7018 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -106,20 +106,20 @@ jobs: os: ubuntu-24.04-arm toxenv: py tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py" - dev_ast_serialize: true + ast_serialize: true - name: Parallel tests with py314-ubuntu, mypyc-compiled python: '3.14' os: ubuntu-24.04-arm toxenv: py tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py" test_mypyc: true - dev_ast_serialize: true + ast_serialize: true - name: Parallel tests with py314-windows-64, interpreted python: '3.14' os: windows-latest toxenv: py tox_extra_args: "-n 2 --mypy-num-workers=2 mypy/test/testcheck.py -k 'incremental or modules or classes'" - dev_ast_serialize: true + ast_serialize: true - name: Type check our own code (py310-ubuntu) python: '3.10' @@ -142,7 +142,7 @@ jobs: timeout-minutes: 60 env: TOX_SKIP_MISSING_INTERPRETERS: False - VIRTUALENV_SYSTEM_SITE_PACKAGES: ${{ matrix.dev_ast_serialize && 1 || 0 }} + VIRTUALENV_SYSTEM_SITE_PACKAGES: ${{ matrix.ast_serialize && 1 || 0 }} # Rich (pip) -- Disable color for windows + pytest FORCE_COLOR: ${{ !(startsWith(matrix.os, 'windows-') && startsWith(matrix.toxenv, 'py')) && 1 || 0 }} # Tox @@ -217,10 +217,10 @@ jobs: pip install -r test-requirements.txt CC=clang MYPYC_OPT_LEVEL=0 MYPY_USE_MYPYC=1 pip install -e . - # To speed-up process until ast_serialize is on PyPI. - - name: Install pinned ast-serialize - if: ${{ matrix.dev_ast_serialize }} - run: pip install ast-serialize@git+https://github.com/mypyc/ast_serialize.git@052c5bfa3b2a5bf07c0b163ccbe2c5ccbfae9ac5 + # It is an optional dependency (for now). + - name: Install ast-serialize + if: ${{ matrix.ast_serialize }} + run: pip install ast-serialize>=0.1.1,<1.0.0 - name: Setup tox environment run: | diff --git a/pyproject.toml b/pyproject.toml index c4b3b644c8d7..55845e70b809 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,7 @@ python2 = [] reports = ["lxml"] install-types = ["pip"] faster-cache = ["orjson"] +native-parse = ["ast-serialize>=0.1.1,<1.0.0"] [project.urls] Homepage = "https://www.mypy-lang.org/" diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 07685793a725..8616a1b6d165 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -6165,7 +6165,7 @@ reveal_type(f3(A())) # E: No overload variant of "f3" matches argument type "A" # N: Revealed type is "Any" reveal_type(f3(B())) # N: Revealed type is "__main__.B" -[case testOverloadIfSplitFunctionDef] +[case testOverloadIfSplitFunctionDef_no_native_parse] # flags: --always-true True --always-false False from typing import overload From d712995f69bed9f95397599a4ad39425c7c14be5 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 16 Mar 2026 20:11:27 +0000 Subject: [PATCH 2/4] Add quotes --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6fe36b8b7018..945629a43021 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -220,7 +220,7 @@ jobs: # It is an optional dependency (for now). - name: Install ast-serialize if: ${{ matrix.ast_serialize }} - run: pip install ast-serialize>=0.1.1,<1.0.0 + run: pip install 'ast-serialize>=0.1.1,<1.0.0' - name: Setup tox environment run: | From 9b02ce862320786f024a849cb833bfa873cc63c2 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 16 Mar 2026 20:17:57 +0000 Subject: [PATCH 3/4] Make ast-serialize non-optional in tests --- .github/workflows/test.yml | 9 --------- test-requirements.in | 1 + test-requirements.txt | 2 ++ 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 945629a43021..435d09259ce9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -106,20 +106,17 @@ jobs: os: ubuntu-24.04-arm toxenv: py tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py" - ast_serialize: true - name: Parallel tests with py314-ubuntu, mypyc-compiled python: '3.14' os: ubuntu-24.04-arm toxenv: py tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py" test_mypyc: true - ast_serialize: true - name: Parallel tests with py314-windows-64, interpreted python: '3.14' os: windows-latest toxenv: py tox_extra_args: "-n 2 --mypy-num-workers=2 mypy/test/testcheck.py -k 'incremental or modules or classes'" - ast_serialize: true - name: Type check our own code (py310-ubuntu) python: '3.10' @@ -142,7 +139,6 @@ jobs: timeout-minutes: 60 env: TOX_SKIP_MISSING_INTERPRETERS: False - VIRTUALENV_SYSTEM_SITE_PACKAGES: ${{ matrix.ast_serialize && 1 || 0 }} # Rich (pip) -- Disable color for windows + pytest FORCE_COLOR: ${{ !(startsWith(matrix.os, 'windows-') && startsWith(matrix.toxenv, 'py')) && 1 || 0 }} # Tox @@ -217,11 +213,6 @@ jobs: pip install -r test-requirements.txt CC=clang MYPYC_OPT_LEVEL=0 MYPY_USE_MYPYC=1 pip install -e . - # It is an optional dependency (for now). - - name: Install ast-serialize - if: ${{ matrix.ast_serialize }} - run: pip install 'ast-serialize>=0.1.1,<1.0.0' - - name: Setup tox environment run: | tox run -e ${{ matrix.toxenv }} --notest diff --git a/test-requirements.in b/test-requirements.in index 9cc276901f89..d8227dcb8923 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -13,3 +13,4 @@ pytest-cov>=2.10.0 setuptools>=77.0.3 tomli>=1.1.0 # needed even on py311+ so the self check passes with --python-version 3.10 pre_commit>=3.5.0 +ast-serialize>=0.1.1,<1.0.0 diff --git a/test-requirements.txt b/test-requirements.txt index 48479e1ea0b6..5f8802825c59 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -4,6 +4,8 @@ # # pip-compile --allow-unsafe --output-file=test-requirements.txt --strip-extras test-requirements.in # +ast-serialize==0.1.1 + # via -r test-requirements.in attrs==25.4.0 # via -r test-requirements.in cfgv==3.4.0 From 179fc3cebc46501278f116ad265deca7beff41ef Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 16 Mar 2026 20:23:26 +0000 Subject: [PATCH 4/4] Add extra to the docs --- docs/source/common_issues.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 31141ad383e1..e67413228035 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -228,11 +228,12 @@ make cold mypy runs several times faster. Furthermore: as of `mypy 1.13 `_, mypy allows use of the orjson library for handling the cache instead of the stdlib json, for -improved performance. You can ensure the presence of orjson using the faster-cache extra: +improved performance. You can ensure the presence of orjson using the ``faster-cache`` extra: python3 -m pip install -U mypy[faster-cache] -Mypy may depend on orjson by default in the future. +Mypy may depend on orjson by default in the future. To use faster, native parser, use the +``native-parse`` extra. Native parser will be default in near future. Types of empty collections --------------------------