From a0ab60b2e0a72bd4ec6ba6ae91a485b10a6015c2 Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 01:13:25 +0300 Subject: [PATCH 01/13] [sys] Add the 3.14 _jit 'module' --- stdlib/VERSIONS | 1 + stdlib/sys/__init__.pyi | 4 ++++ stdlib/sys/__jit.pyi | 11 +++++++++++ stdlib/sys/_monitoring.pyi | 3 ++- 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 stdlib/sys/__jit.pyi diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index e26bb8da2574..45a141a0c1b7 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -296,6 +296,7 @@ symbol: 3.0-3.9 symtable: 3.0- sys: 3.0- sys._monitoring: 3.12- # Doesn't actually exist. See comments in the stub. +sys.__jit: 3.14- # Similar to sys._monitoring sysconfig: 3.0- syslog: 3.0- tabnanny: 3.0- diff --git a/stdlib/sys/__init__.pyi b/stdlib/sys/__init__.pyi index 6abef85dfb7f..a3aa366f0c7e 100644 --- a/stdlib/sys/__init__.pyi +++ b/stdlib/sys/__init__.pyi @@ -518,3 +518,7 @@ if sys.version_info >= (3, 14): def is_remote_debug_enabled() -> bool: ... def remote_exec(pid: int, script: StrOrBytesPath) -> None: ... def _is_immortal(op: object, /) -> bool: ... + + from . import __jit + + _jit = __jit diff --git a/stdlib/sys/__jit.pyi b/stdlib/sys/__jit.pyi new file mode 100644 index 000000000000..90fb65c1d9ef --- /dev/null +++ b/stdlib/sys/__jit.pyi @@ -0,0 +1,11 @@ +# This py314+ module provides annotations for `sys._jit`. +# It's named `sys.__jit` in typeshed, +# because trying to import `sys._jit` will fail at runtime! +# At runtime, `sys._jit` has the unusual status +# of being a `types.ModuleType` instance that cannot be directly imported, +# (same as sys.monitoring) +# and exists in the `sys`-module namespace despite `sys` not being a package. + +def is_available() -> bool: ... +def is_enabled() -> bool: ... +def is_active() -> bool: ... diff --git a/stdlib/sys/_monitoring.pyi b/stdlib/sys/_monitoring.pyi index 83f1e7dd0f1d..b999d63f6470 100644 --- a/stdlib/sys/_monitoring.pyi +++ b/stdlib/sys/_monitoring.pyi @@ -1,8 +1,9 @@ # This py312+ module provides annotations for `sys.monitoring`. # It's named `sys._monitoring` in typeshed, # because trying to import `sys.monitoring` will fail at runtime! -# At runtime, `sys.monitoring` has the unique status +# At runtime, `sys.monitoring` has the unusual status # of being a `types.ModuleType` instance that cannot be directly imported, +# (same as sys._jit) # and exists in the `sys`-module namespace despite `sys` not being a package. import sys From cf8038e6b2ecae4254cd6a3f2409c70d78f9d2ae Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 01:29:07 +0300 Subject: [PATCH 02/13] Add sys.__jit to stubtest_allowlists --- stdlib/@tests/stubtest_allowlists/py314.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index bc2c485d7db8..19d7eb49d6a6 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -132,6 +132,7 @@ importlib.metadata.DeprecatedNonAbstract.__new__ importlib.resources._common.files sys._monitoring # Doesn't really exist. See comments in the stub. +sys.__jit # Similar to sys._monitoring sys.last_exc # not always defined # These only exist to give a better error message if you try to subclass an instance From 31b375b66beee259b544a00ed577072931e65c21 Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 01:35:30 +0300 Subject: [PATCH 03/13] Move sys.__jit before sys._monitoring in VERSIONS to keep it sorted --- stdlib/VERSIONS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index 45a141a0c1b7..fddf18cf7945 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -295,8 +295,8 @@ sunau: 3.0-3.12 symbol: 3.0-3.9 symtable: 3.0- sys: 3.0- -sys._monitoring: 3.12- # Doesn't actually exist. See comments in the stub. sys.__jit: 3.14- # Similar to sys._monitoring +sys._monitoring: 3.12- # Doesn't actually exist. See comments in the stub. sysconfig: 3.0- syslog: 3.0- tabnanny: 3.0- From cf2aa4efc45352a12c589e11fbf71924ac0ce84e Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 01:45:17 +0300 Subject: [PATCH 04/13] Change how monitoring and _jit are imported to not include the _ prefixed modules in its variable list --- stdlib/sys/__init__.pyi | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/stdlib/sys/__init__.pyi b/stdlib/sys/__init__.pyi index a3aa366f0c7e..699c9846ae9b 100644 --- a/stdlib/sys/__init__.pyi +++ b/stdlib/sys/__init__.pyi @@ -510,15 +510,11 @@ if sys.version_info >= (3, 12): else: def activate_stack_trampoline(backend: str, /) -> NoReturn: ... - from . import _monitoring - - monitoring = _monitoring + from . import _monitoring as monitoring if sys.version_info >= (3, 14): def is_remote_debug_enabled() -> bool: ... def remote_exec(pid: int, script: StrOrBytesPath) -> None: ... def _is_immortal(op: object, /) -> bool: ... - from . import __jit - - _jit = __jit + from . import __jit as _jit From 30262c465c1dd47c962f7572a68e5981f2706dc1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 2 May 2026 22:51:11 +0000 Subject: [PATCH 05/13] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/sys/__init__.pyi | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stdlib/sys/__init__.pyi b/stdlib/sys/__init__.pyi index 699c9846ae9b..3264117afd13 100644 --- a/stdlib/sys/__init__.pyi +++ b/stdlib/sys/__init__.pyi @@ -510,11 +510,7 @@ if sys.version_info >= (3, 12): else: def activate_stack_trampoline(backend: str, /) -> NoReturn: ... - from . import _monitoring as monitoring - if sys.version_info >= (3, 14): def is_remote_debug_enabled() -> bool: ... def remote_exec(pid: int, script: StrOrBytesPath) -> None: ... def _is_immortal(op: object, /) -> bool: ... - - from . import __jit as _jit From 6c8e98c15b3932ad297e69ecdf9f6d4db9f27f0c Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 02:34:39 +0300 Subject: [PATCH 06/13] Silence the unused import errors --- stdlib/sys/__init__.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/sys/__init__.pyi b/stdlib/sys/__init__.pyi index 3264117afd13..1f6807df6f8c 100644 --- a/stdlib/sys/__init__.pyi +++ b/stdlib/sys/__init__.pyi @@ -510,7 +510,11 @@ if sys.version_info >= (3, 12): else: def activate_stack_trampoline(backend: str, /) -> NoReturn: ... + from . import _monitoring as monitoring # noqa: F401 # pyright: ignore[reportUnusedImport] + if sys.version_info >= (3, 14): def is_remote_debug_enabled() -> bool: ... def remote_exec(pid: int, script: StrOrBytesPath) -> None: ... def _is_immortal(op: object, /) -> bool: ... + + from . import __jit as _jit # noqa: F401 # pyright: ignore[reportUnusedImport] From cf2f23ab383dc4e14a1e31c14f53a7f8155faa96 Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 03:29:22 +0300 Subject: [PATCH 07/13] Revert the imports --- stdlib/sys/__init__.pyi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/sys/__init__.pyi b/stdlib/sys/__init__.pyi index 1f6807df6f8c..a3aa366f0c7e 100644 --- a/stdlib/sys/__init__.pyi +++ b/stdlib/sys/__init__.pyi @@ -510,11 +510,15 @@ if sys.version_info >= (3, 12): else: def activate_stack_trampoline(backend: str, /) -> NoReturn: ... - from . import _monitoring as monitoring # noqa: F401 # pyright: ignore[reportUnusedImport] + from . import _monitoring + + monitoring = _monitoring if sys.version_info >= (3, 14): def is_remote_debug_enabled() -> bool: ... def remote_exec(pid: int, script: StrOrBytesPath) -> None: ... def _is_immortal(op: object, /) -> bool: ... - from . import __jit as _jit # noqa: F401 # pyright: ignore[reportUnusedImport] + from . import __jit + + _jit = __jit From be34b668eec76e2f3a0721ee54c53610a61cab04 Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 04:42:30 +0300 Subject: [PATCH 08/13] Add test cases for sys._jit --- stdlib/@tests/test_cases/sys/check_jit.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 stdlib/@tests/test_cases/sys/check_jit.py diff --git a/stdlib/@tests/test_cases/sys/check_jit.py b/stdlib/@tests/test_cases/sys/check_jit.py new file mode 100644 index 000000000000..c6a2a8eef6e0 --- /dev/null +++ b/stdlib/@tests/test_cases/sys/check_jit.py @@ -0,0 +1,10 @@ +import sys +from typing_extensions import assert_type + +if sys.version_info >= (3, 14): + assert_type(sys._jit.is_available(), bool) + assert_type(sys._jit.is_enabled(), bool) + assert_type(sys._jit.is_active(), bool) + + # sys is not a package, so this should be an error + import sys._jit # type: ignore From 2d1a7be883a24c930b57e308000095a66d0c5f57 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 3 May 2026 01:44:30 +0000 Subject: [PATCH 09/13] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/@tests/test_cases/sys/check_jit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/@tests/test_cases/sys/check_jit.py b/stdlib/@tests/test_cases/sys/check_jit.py index c6a2a8eef6e0..b4b837164bdd 100644 --- a/stdlib/@tests/test_cases/sys/check_jit.py +++ b/stdlib/@tests/test_cases/sys/check_jit.py @@ -7,4 +7,4 @@ assert_type(sys._jit.is_active(), bool) # sys is not a package, so this should be an error - import sys._jit # type: ignore + import sys._jit # type: ignore From bdc598509d1a9b167031ee2bf245d5da6c78e7f6 Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 05:48:06 +0300 Subject: [PATCH 10/13] Fix the negative test for import sys._jit on pyright --- stdlib/@tests/test_cases/sys/check_jit.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stdlib/@tests/test_cases/sys/check_jit.py b/stdlib/@tests/test_cases/sys/check_jit.py index b4b837164bdd..4e3afac7c54f 100644 --- a/stdlib/@tests/test_cases/sys/check_jit.py +++ b/stdlib/@tests/test_cases/sys/check_jit.py @@ -8,3 +8,8 @@ # sys is not a package, so this should be an error import sys._jit # type: ignore + + def sys_is_not_a_package(): + # This has to be put into a function, because otherwise pyright + # applies the type: ignore on the import sys._jit to the above usages of it + import sys._jit # type: ignore From a0a01f09edd8be3405409799ba4d01e317bf71b1 Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 05:49:29 +0300 Subject: [PATCH 11/13] Wow, i didnt resolve the merge conflict with the pre-commit CI correctly --- stdlib/@tests/test_cases/sys/check_jit.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/stdlib/@tests/test_cases/sys/check_jit.py b/stdlib/@tests/test_cases/sys/check_jit.py index 4e3afac7c54f..6b263162945a 100644 --- a/stdlib/@tests/test_cases/sys/check_jit.py +++ b/stdlib/@tests/test_cases/sys/check_jit.py @@ -6,9 +6,6 @@ assert_type(sys._jit.is_enabled(), bool) assert_type(sys._jit.is_active(), bool) - # sys is not a package, so this should be an error - import sys._jit # type: ignore - def sys_is_not_a_package(): # This has to be put into a function, because otherwise pyright # applies the type: ignore on the import sys._jit to the above usages of it From ee2a5663627f05a231e81b97f441c7538afd1218 Mon Sep 17 00:00:00 2001 From: lambda-abstraction Date: Sun, 3 May 2026 06:12:23 +0300 Subject: [PATCH 12/13] I love wasting CPU time running CI just to get a stupid error --- stdlib/@tests/test_cases/sys/check_jit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/@tests/test_cases/sys/check_jit.py b/stdlib/@tests/test_cases/sys/check_jit.py index 6b263162945a..30264a78ec9f 100644 --- a/stdlib/@tests/test_cases/sys/check_jit.py +++ b/stdlib/@tests/test_cases/sys/check_jit.py @@ -6,7 +6,7 @@ assert_type(sys._jit.is_enabled(), bool) assert_type(sys._jit.is_active(), bool) - def sys_is_not_a_package(): + def sys_is_not_a_package() -> None: # This has to be put into a function, because otherwise pyright # applies the type: ignore on the import sys._jit to the above usages of it import sys._jit # type: ignore From bcf0601de287e2f1f09261137d83c9216aa94fbc Mon Sep 17 00:00:00 2001 From: lambda-abstraction <41861454+lambda-abstraction@users.noreply.github.com> Date: Mon, 4 May 2026 02:27:49 +0300 Subject: [PATCH 13/13] Remove the claim of the issue cause in the test case, as its not confirmed Co-authored-by: Jelle Zijlstra --- stdlib/@tests/test_cases/sys/check_jit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/@tests/test_cases/sys/check_jit.py b/stdlib/@tests/test_cases/sys/check_jit.py index 30264a78ec9f..7916218ceda4 100644 --- a/stdlib/@tests/test_cases/sys/check_jit.py +++ b/stdlib/@tests/test_cases/sys/check_jit.py @@ -7,6 +7,6 @@ assert_type(sys._jit.is_active(), bool) def sys_is_not_a_package() -> None: - # This has to be put into a function, because otherwise pyright - # applies the type: ignore on the import sys._jit to the above usages of it + # This has to be put into a function, because otherwise the presence + # of this import statement causes errors on the above usages of `sys._jit`. import sys._jit # type: ignore