From 392eb4aa5a5130c8f4371cb0465cf6c1441c2119 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 1 Dec 2016 03:51:41 -0800 Subject: [PATCH] add stubs for Python 2 profile and cProfile (#699) * add stubs for Python 2 profile and cProfile Partially fixes #531. Contrary to the Python 2.7 docs at https://docs.python.org/2/library/profile.html#module-cProfile, these modules do not have exactly the same interface. For example, profile.Profile() does not have an enable() method. * profile stubs: move to 2and3, add __init__, use private names for typevars --- stdlib/2and3/cProfile.pyi | 18 ++++++++++++++++++ stdlib/2and3/profile.pyi | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 stdlib/2and3/cProfile.pyi create mode 100644 stdlib/2and3/profile.pyi diff --git a/stdlib/2and3/cProfile.pyi b/stdlib/2and3/cProfile.pyi new file mode 100644 index 000000000..b31ea0337 --- /dev/null +++ b/stdlib/2and3/cProfile.pyi @@ -0,0 +1,18 @@ +from typing import Any, Callable, Dict, Optional, TypeVar + +def run(statement: str, filename: Optional[str] = ..., sort: int = ...) -> None: ... +def runctx(statement: str, globals: Dict[str, Any], locals: Dict[str, Any], filename: Optional[str] = ..., sort: int = ...) -> None: ... + +_SelfT = TypeVar('_SelfT', bound='Profile') +_T = TypeVar('_T') + +class Profile: + def __init__(self, custom_timer: Callable[[], float] = ..., time_unit: float = ..., subcalls: bool = ..., builtins: bool = ...) -> None: ... + def enable(self) -> None: ... + def disable(self) -> None: ... + def print_stats(self, sort: int = ...) -> None: ... + def dump_stats(self, file: str) -> None: ... + def create_stats(self) -> None: ... + def run(self: _SelfT, cmd: str) -> _SelfT: ... + def runctx(self: _SelfT, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _SelfT: ... + def runcall(self, func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ... diff --git a/stdlib/2and3/profile.pyi b/stdlib/2and3/profile.pyi new file mode 100644 index 000000000..21a7c8fd4 --- /dev/null +++ b/stdlib/2and3/profile.pyi @@ -0,0 +1,21 @@ +from typing import Any, Callable, Dict, Optional, TypeVar + +def run(statement: str, filename: Optional[str] = ..., sort: int = ...) -> None: ... +def runctx(statement: str, globals: Dict[str, Any], locals: Dict[str, Any], filename: Optional[str] = ..., sort: int = ...) -> None: ... + +_SelfT = TypeVar('_SelfT', bound='Profile') +_T = TypeVar('_T') + +class Profile: + def __init__(self, timer: Optional[Callable[[], float]] = ..., bias: Optional[int] = ...) -> None: ... + def set_cmd(self, cmd: str) -> None: ... + def simulate_call(self, name: str) -> None: ... + def simulate_cmd_complete(self) -> None: ... + def print_stats(self, sort: int = ...) -> None: ... + def dump_stats(self, file: str) -> None: ... + def create_stats(self) -> None: ... + def snapshot_stats(self) -> None: ... + def run(self: _SelfT, cmd: str) -> _SelfT: ... + def runctx(self: _SelfT, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _SelfT: ... + def runcall(self, func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ... + def calibrate(self, m: int, verbose: int = ...) -> float: ...