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 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..7916218ceda4 --- /dev/null +++ b/stdlib/@tests/test_cases/sys/check_jit.py @@ -0,0 +1,12 @@ +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) + + def sys_is_not_a_package() -> None: + # 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 diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index e26bb8da2574..fddf18cf7945 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -295,6 +295,7 @@ sunau: 3.0-3.12 symbol: 3.0-3.9 symtable: 3.0- sys: 3.0- +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- 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