Skip to content

Commit b92febf

Browse files
johnslavikCopilot
andcommitted
Add typed stubs for the profiling stdlib package
- Complete type annotations for profiling.tracing and profiling.sampling - Replace all Incomplete usages with proper types throughout - Add return types, parameter types, and attribute types to all stubs - Only exception: unwinder: Incomplete in sample.pyi (_remote_debugging C ext) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5d41fd6 commit b92febf

30 files changed

+972
-2
lines changed

stdlib/VERSIONS

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ binhex: 3.0-3.10
107107
bisect: 3.0-
108108
builtins: 3.0-
109109
bz2: 3.0-
110-
cProfile: 3.0-
110+
cProfile: 3.0-3.17
111111
calendar: 3.0-
112112
cgi: 3.0-3.12
113113
cgitb: 3.0-3.12
@@ -245,7 +245,8 @@ poplib: 3.0-
245245
posix: 3.0-
246246
posixpath: 3.0-
247247
pprint: 3.0-
248-
profile: 3.0-
248+
profile: 3.0-3.17
249+
profiling: 3.15-
249250
pstats: 3.0-
250251
pty: 3.0-
251252
pwd: 3.0-

stdlib/profiling/__init__.pyi

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from .collector import Collector as Collector
2+
from .gecko_collector import GeckoCollector as GeckoCollector
3+
from .heatmap_collector import HeatmapCollector as HeatmapCollector
4+
from .pstats_collector import PstatsCollector as PstatsCollector
5+
from .stack_collector import CollapsedStackCollector as CollapsedStackCollector
6+
from .string_table import StringTable as StringTable
7+
8+
__all__ = ["Collector", "PstatsCollector", "CollapsedStackCollector", "HeatmapCollector", "GeckoCollector", "StringTable"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from .cli import main as main
2+
from .errors import (
3+
SamplingModuleNotFoundError as SamplingModuleNotFoundError,
4+
SamplingScriptNotFoundError as SamplingScriptNotFoundError,
5+
SamplingUnknownProcessError as SamplingUnknownProcessError,
6+
)
7+
8+
MACOS_PERMISSION_ERROR: str
9+
LINUX_PERMISSION_ERROR: str
10+
WINDOWS_PERMISSION_ERROR: str
11+
GENERIC_PERMISSION_ERROR: str
12+
13+
def handle_permission_error() -> None: ...
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import types
2+
from typing import Any
3+
from typing_extensions import Self
4+
5+
def get_child_pids(pid: int, recursive: bool = True) -> list[int]: ...
6+
def is_python_process(pid: int) -> bool: ...
7+
8+
class ChildProcessMonitor:
9+
parent_pid: int
10+
cli_args: list[str]
11+
output_pattern: str
12+
def __init__(self, pid: int, cli_args: list[str], output_pattern: str) -> None: ...
13+
def __enter__(self) -> Self: ...
14+
def __exit__(
15+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
16+
) -> None: ...
17+
@property
18+
def spawned_profilers(self) -> list[Any]: ...
19+
def wait_for_profilers(self, timeout: float = ...) -> None: ...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def get_combined_css(component: str) -> str: ...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def fmt(value: float, decimals: int = 1) -> str: ...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from typing import Never
2+
3+
class CoordinatorError(Exception): ...
4+
class ArgumentError(CoordinatorError): ...
5+
class SyncError(CoordinatorError): ...
6+
class TargetError(CoordinatorError): ...
7+
8+
def main() -> Never: ...
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import types
2+
from _typeshed import StrOrBytesPath
3+
from typing import Any
4+
from typing_extensions import Self
5+
6+
from .collector import Collector as Collector
7+
8+
COMPRESSION_NONE: int
9+
COMPRESSION_ZSTD: int
10+
11+
class BinaryCollector(Collector):
12+
filename: str
13+
sample_interval_usec: int
14+
skip_idle: bool
15+
def __init__(self, filename: str, sample_interval_usec: int, *, skip_idle: bool = False, compression: str = "auto") -> None: ...
16+
def collect(self, stack_frames: Any, timestamp_us: int | None = None) -> None: ...
17+
def collect_failed_sample(self) -> None: ...
18+
def export(self, filename: StrOrBytesPath | None = None) -> None: ...
19+
@property
20+
def total_samples(self) -> int: ...
21+
def get_stats(self) -> dict[str, Any]: ...
22+
def __enter__(self) -> Self: ...
23+
def __exit__(
24+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
25+
) -> None: ...
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import types
2+
from _typeshed import StrOrBytesPath
3+
from collections.abc import Callable
4+
from typing import Any
5+
from typing_extensions import Self
6+
7+
from .collector import Collector as Collector
8+
from .gecko_collector import GeckoCollector as GeckoCollector
9+
from .pstats_collector import PstatsCollector as PstatsCollector
10+
from .stack_collector import CollapsedStackCollector as CollapsedStackCollector, FlamegraphCollector as FlamegraphCollector
11+
12+
class BinaryReader:
13+
filename: str
14+
def __init__(self, filename: str) -> None: ...
15+
def __enter__(self) -> Self: ...
16+
def __exit__(
17+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
18+
) -> None: ...
19+
def get_info(self) -> dict[str, Any]: ...
20+
def replay_samples(self, collector: Collector, progress_callback: Callable[[int, int], None] | None = None) -> int: ...
21+
@property
22+
def sample_count(self) -> int: ...
23+
def get_stats(self) -> dict[str, Any]: ...
24+
25+
def convert_binary_to_format(
26+
input_file: StrOrBytesPath,
27+
output_file: StrOrBytesPath,
28+
output_format: str,
29+
sample_interval_usec: int | None = None,
30+
progress_callback: Callable[[int, int], None] | None = None,
31+
) -> None: ...

0 commit comments

Comments
 (0)