Skip to content

Commit 838dd3a

Browse files
Add sys.monitoring from Python 3.12 (#10890)
Co-authored-by: Alex Waygood <[email protected]>
1 parent bb27e6c commit 838dd3a

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

stdlib/VERSIONS

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ sunau: 2.7-
250250
symbol: 2.7-3.9
251251
symtable: 2.7-
252252
sys: 2.7-
253+
sys._monitoring: 3.12- # Doesn't actually exist. See comments in the stub.
253254
sysconfig: 2.7-
254255
syslog: 2.7-
255256
tabnanny: 2.7-

stdlib/sys.pyi renamed to stdlib/sys/__init__.pyi

+4
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,7 @@ if sys.version_info >= (3, 12):
370370
def activate_stack_trampoline(__backend: str) -> None: ...
371371
else:
372372
def activate_stack_trampoline(__backend: str) -> NoReturn: ...
373+
374+
from . import _monitoring
375+
376+
monitoring = _monitoring

stdlib/sys/_monitoring.pyi

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This py312+ module provides annotations for `sys.monitoring`.
2+
# It's named `sys._monitoring` in typeshed,
3+
# because trying to import `sys.monitoring` will fail at runtime!
4+
# At runtime, `sys.monitoring` has the unique status
5+
# of being a `types.ModuleType` instance that cannot be directly imported,
6+
# and exists in the `sys`-module namespace despite `sys` not being a package.
7+
8+
from collections.abc import Callable
9+
from types import CodeType
10+
from typing import Any
11+
12+
DEBUGGER_ID: int
13+
COVERAGE_ID: int
14+
PROFILER_ID: int
15+
OPTIMIZER_ID: int
16+
17+
def use_tool_id(__tool_id: int, __name: str) -> None: ...
18+
def free_tool_id(__tool_id: int) -> None: ...
19+
def get_tool(__tool_id: int) -> str | None: ...
20+
21+
events: _events
22+
23+
class _events:
24+
BRANCH: int
25+
CALL: int
26+
C_RAISE: int
27+
C_RETURN: int
28+
EXCEPTION_HANDLED: int
29+
INSTRUCTION: int
30+
JUMP: int
31+
LINE: int
32+
NO_EVENTS: int
33+
PY_RESUME: int
34+
PY_RETURN: int
35+
PY_START: int
36+
PY_THROW: int
37+
PY_UNWIND: int
38+
PY_YIELD: int
39+
RAISE: int
40+
RERAISE: int
41+
STOP_ITERATION: int
42+
43+
def get_events(__tool_id: int) -> int: ...
44+
def set_events(__tool_id: int, __event_set: int) -> None: ...
45+
def get_local_events(__tool_id: int, __code: CodeType) -> int: ...
46+
def set_local_events(__tool_id: int, __code: CodeType, __event_set: int) -> int: ...
47+
def restart_events() -> None: ... # undocumented
48+
49+
DISABLE: object
50+
MISSING: object
51+
52+
def register_callback(__tool_id: int, __event: int, __func: Callable[..., Any] | None) -> Callable[..., Any] | None: ...

tests/stubtest_allowlists/py312.txt

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all Pat
6969
types.GenericAlias.__call__ # Would be complicated to fix properly, Any could silence problems. #6392
7070
types.GenericAlias.__getattr__
7171
types.GenericAlias.__mro_entries__
72+
sys._monitoring # Doesn't really exist. See comments in the stub.
7273
weakref.ProxyType.__reversed__ # Doesn't really exist
7374

7475
# C signature is broader than what is actually accepted

0 commit comments

Comments
 (0)