From 943d04ada1b660a81c20f77c4f670650f7af0788 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 9 Dec 2025 12:38:55 +0000 Subject: [PATCH 1/4] Fail with an explicit error on PyPy --- mypy-requirements.txt | 2 +- mypy/build.py | 10 +++++++++- pyproject.toml | 4 ++-- test-requirements.txt | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/mypy-requirements.txt b/mypy-requirements.txt index b0c632dddac5..6984d9a5d070 100644 --- a/mypy-requirements.txt +++ b/mypy-requirements.txt @@ -4,4 +4,4 @@ typing_extensions>=4.6.0 mypy_extensions>=1.0.0 pathspec>=0.9.0 tomli>=1.1.0; python_version<'3.11' -librt>=0.6.2 +librt>=0.6.2; platform_python_implementation != 'PyPy' diff --git a/mypy/build.py b/mypy/build.py index d6d6a8ba9094..eeebcb770030 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -40,7 +40,15 @@ TypedDict, ) -from librt.internal import cache_version +try: + from librt.internal import cache_version +except ImportError: + print( + "Running mypy on PyPy is not supported yet." + "To type-check a PyPy library please run mypy on an equivalent CPython version," + "see https://github.com/mypyc/librt/issues/16 for possible workarounds." + ) + sys.exit(2) import mypy.semanal_main from mypy.cache import CACHE_VERSION, CacheMeta, ReadBuffer, WriteBuffer, write_json diff --git a/pyproject.toml b/pyproject.toml index 38596ac2609d..54d2263a03f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ requires = [ "mypy_extensions>=1.0.0", "pathspec>=0.9.0", "tomli>=1.1.0; python_version<'3.11'", - "librt>=0.6.2", + "librt>=0.6.2; platform_python_implementation != 'PyPy'", # the following is from build-requirements.txt "types-psutil", "types-setuptools", @@ -53,7 +53,7 @@ dependencies = [ "mypy_extensions>=1.0.0", "pathspec>=0.9.0", "tomli>=1.1.0; python_version<'3.11'", - "librt>=0.6.2", + "librt>=0.6.2; platform_python_implementation != 'PyPy'", ] dynamic = ["version"] diff --git a/test-requirements.txt b/test-requirements.txt index 3dab107eba61..883930c681a4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -22,7 +22,7 @@ identify==2.6.15 # via pre-commit iniconfig==2.1.0 # via pytest -librt==0.6.2 +librt==0.7.3 ; platform_python_implementation != 'PyPy' # via -r mypy-requirements.txt lxml==6.0.2 ; python_version < "3.15" # via -r test-requirements.in From 17677fcb0636d965c726ae5b81fbac180a2db67d Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 9 Dec 2025 12:43:25 +0000 Subject: [PATCH 2/4] Print error conditionally --- mypy/build.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index eeebcb770030..80f2bc6c34c1 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -43,12 +43,15 @@ try: from librt.internal import cache_version except ImportError: - print( - "Running mypy on PyPy is not supported yet." - "To type-check a PyPy library please run mypy on an equivalent CPython version," - "see https://github.com/mypyc/librt/issues/16 for possible workarounds." - ) - sys.exit(2) + if platform.python_implementation() == "PyPy": + print( + "Running mypy on PyPy is not supported yet." + "To type-check a PyPy library please run mypy on an equivalent CPython version," + "see https://github.com/mypyc/librt/issues/16 for possible workarounds." + ) + sys.exit(2) + else: + raise import mypy.semanal_main from mypy.cache import CACHE_VERSION, CacheMeta, ReadBuffer, WriteBuffer, write_json From 3bf9c9ded4778abb5a7d548898b8dca6087fd40d Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 9 Dec 2025 12:54:16 +0000 Subject: [PATCH 3/4] Fail in setup.py instead --- mypy/build.py | 13 +------------ setup.py | 9 +++++++++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index 80f2bc6c34c1..d6d6a8ba9094 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -40,18 +40,7 @@ TypedDict, ) -try: - from librt.internal import cache_version -except ImportError: - if platform.python_implementation() == "PyPy": - print( - "Running mypy on PyPy is not supported yet." - "To type-check a PyPy library please run mypy on an equivalent CPython version," - "see https://github.com/mypyc/librt/issues/16 for possible workarounds." - ) - sys.exit(2) - else: - raise +from librt.internal import cache_version import mypy.semanal_main from mypy.cache import CACHE_VERSION, CacheMeta, ReadBuffer, WriteBuffer, write_json diff --git a/setup.py b/setup.py index 2892bdc64f38..47ea432fbfb5 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ import glob import os import os.path +import platform import sys from typing import TYPE_CHECKING, Any @@ -12,6 +13,14 @@ sys.stderr.write("ERROR: You need Python 3.10 or later to use mypy.\n") exit(1) +if platform.python_implementation() == "PyPy": + print( + "ERROR: Running mypy on PyPy is not supported yet." + "To type-check a PyPy library please use an equivalent CPython version," + "see https://github.com/mypyc/librt/issues/16 for possible workarounds." + ) + sys.exit(1) + # we'll import stuff from the source tree, let's ensure is on the sys path sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) From 32b0cffaa5844a2cb5beb11638f95622ccaee581 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 9 Dec 2025 13:35:12 +0000 Subject: [PATCH 4/4] Use stderr for consistency --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 47ea432fbfb5..bc45d90354e5 100644 --- a/setup.py +++ b/setup.py @@ -14,12 +14,12 @@ exit(1) if platform.python_implementation() == "PyPy": - print( - "ERROR: Running mypy on PyPy is not supported yet." - "To type-check a PyPy library please use an equivalent CPython version," - "see https://github.com/mypyc/librt/issues/16 for possible workarounds." + sys.stderr.write( + "ERROR: Running mypy on PyPy is not supported yet.\n" + "To type-check a PyPy library please use an equivalent CPython version,\n" + "see https://github.com/mypyc/librt/issues/16 for possible workarounds.\n" ) - sys.exit(1) + exit(1) # we'll import stuff from the source tree, let's ensure is on the sys path sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))