From e14cc1970d55173179de7f605a62433affe29c7a Mon Sep 17 00:00:00 2001 From: joncrall Date: Thu, 3 Aug 2023 20:52:26 -0400 Subject: [PATCH] Add doctypes --- line_profiler/__init__.py | 5 +- line_profiler/__main__.pyi | 1 + line_profiler/ipython_extension.pyi | 7 +++ line_profiler/line_profiler.py | 4 +- line_profiler/line_profiler.pyi | 98 +++++++++++++++++++++++++++++ line_profiler/py.typed | 0 pyproject.toml | 1 + setup.py | 1 + 8 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 line_profiler/__main__.pyi create mode 100644 line_profiler/ipython_extension.pyi create mode 100644 line_profiler/line_profiler.pyi create mode 100644 line_profiler/py.typed diff --git a/line_profiler/__init__.py b/line_profiler/__init__.py index 93d77008..3cdfed4c 100644 --- a/line_profiler/__init__.py +++ b/line_profiler/__init__.py @@ -12,7 +12,10 @@ """ -from .line_profiler import __version__ +# from .line_profiler import __version__ + +# NOTE: This needs to be in sync with ../kernprof.py and line_profiler.py +__version__ = '4.0.4' from .line_profiler import (LineProfiler, load_ipython_extension, load_stats, main, diff --git a/line_profiler/__main__.pyi b/line_profiler/__main__.pyi new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/line_profiler/__main__.pyi @@ -0,0 +1 @@ + diff --git a/line_profiler/ipython_extension.pyi b/line_profiler/ipython_extension.pyi new file mode 100644 index 00000000..acbb4d13 --- /dev/null +++ b/line_profiler/ipython_extension.pyi @@ -0,0 +1,7 @@ +from IPython.core.magic import Magics + + +class LineProfilerMagics(Magics): + + def lprun(self, parameter_s: str = ...): + ... diff --git a/line_profiler/line_profiler.py b/line_profiler/line_profiler.py index 54ea60b3..3ef78a4b 100755 --- a/line_profiler/line_profiler.py +++ b/line_profiler/line_profiler.py @@ -16,7 +16,7 @@ f'Has it been compiled? Underlying error is ex={ex!r}' ) -# NOTE: This needs to be in sync with ../kernprof.py +# NOTE: This needs to be in sync with ../kernprof.py and __init__.py __version__ = '4.0.4' @@ -231,7 +231,7 @@ def show_func(filename, start_lineno, func_name, timings, unit, output_unit (float | None): Output unit (in seconds) in which the timing info is displayed. - stream (io.TextIO | None): + stream (io.TextIOBase | None): defaults to sys.stdout stripzeros (bool): diff --git a/line_profiler/line_profiler.pyi b/line_profiler/line_profiler.pyi new file mode 100644 index 00000000..286cebf4 --- /dev/null +++ b/line_profiler/line_profiler.pyi @@ -0,0 +1,98 @@ +from typing import List +from typing import Tuple +import io +from ._line_profiler import LineProfiler as CLineProfiler +from _typeshed import Incomplete + + +def load_ipython_extension(ip) -> None: + ... + + +def is_coroutine(f): + ... + + +CO_GENERATOR: int + + +def is_generator(f): + ... + + +def is_classmethod(f): + ... + + +class LineProfiler(CLineProfiler): + + def __call__(self, func): + ... + + def wrap_classmethod(self, func): + ... + + def wrap_coroutine(self, func): + ... + + def wrap_generator(self, func): + ... + + def wrap_function(self, func): + ... + + def dump_stats(self, filename) -> None: + ... + + def print_stats(self, + stream: Incomplete | None = ..., + output_unit: Incomplete | None = ..., + stripzeros: bool = ..., + summarize: bool = ..., + sort: bool = ...) -> None: + ... + + def run(self, cmd): + ... + + def runctx(self, cmd, globals, locals): + ... + + def runcall(self, func, *args, **kw): + ... + + def add_module(self, mod): + ... + + +def is_ipython_kernel_cell(filename): + ... + + +def show_func(filename: str, + start_lineno: int, + func_name: str, + timings: List[Tuple[int, int, float]], + unit: float, + output_unit: float | None = None, + stream: io.TextIOBase | None = None, + stripzeros: bool = False) -> None: + ... + + +def show_text(stats, + unit, + output_unit: Incomplete | None = ..., + stream: Incomplete | None = ..., + stripzeros: bool = ..., + summarize: bool = ..., + sort: bool = ...): + ... + + +def load_stats(filename): + ... + + +def main(): + ... diff --git a/line_profiler/py.typed b/line_profiler/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/pyproject.toml b/pyproject.toml index 46ce0180..22323ea3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,7 @@ description = "Line-by-line profiler" url = "https://github.com/pyutils/line_profiler" license = "BSD" dev_status = "stable" +typed = true [tool.pytest.ini_options] addopts = "--ignore-glob=setup.py --ignore-glob=dev" diff --git a/setup.py b/setup.py index 30c630ac..8edf70a8 100755 --- a/setup.py +++ b/setup.py @@ -273,6 +273,7 @@ def run_cythonize(force=False): setupkw["py_modules"] = ['kernprof', 'line_profiler'] setupkw["python_requires"] = ">=3.6" setupkw['license_files'] = ['LICENSE.txt', 'LICENSE_Python.txt'] + setupkw["package_data"] = {"line_profiler": ["py.typed", "*.pyi"]} setupkw['keywords'] = ['timing', 'timer', 'profiling', 'profiler', 'line_profiler'] setupkw["classifiers"] = [ 'Development Status :: 5 - Production/Stable',