Skip to content

Commit f8e40f6

Browse files
authored
Merge pull request #432 from dkuettel/typing
dont destroy type of decorated function
2 parents a5ec7fd + 4940bca commit f8e40f6

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

line_profiler/autoprofile/profmod_extractor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ def _ast_get_imports_from_tree(
157157
tree_index (int):
158158
the index of the import as found in the tree
159159
"""
160-
module_dict_list = []
160+
module_dict_list: list[dict[str, str | int | None]] = []
161+
module_dict: dict[str, str | int | None]
161162
modname_list = []
162163
for idx, node in enumerate(tree.body):
163164
if isinstance(node, ast.Import):

line_profiler/explicit_profiler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def func4():
171171
import pathlib
172172
import sys
173173
import typing
174-
from typing import Any, Callable, TypeVar
174+
from typing import Any, Callable, ParamSpec, TypeVar
175175

176176
if typing.TYPE_CHECKING:
177177
ConfigArg = str | pathlib.PurePath | bool | None
@@ -183,6 +183,8 @@ def func4():
183183
from .toml_config import ConfigSource
184184

185185
F = TypeVar('F', bound=Callable[..., Any])
186+
P = ParamSpec('P')
187+
R = TypeVar('R')
186188

187189
# The first process that enables profiling records its PID here. Child processes
188190
# created via multiprocessing (spawn/forkserver) inherit this environment value,
@@ -427,7 +429,7 @@ def disable(self) -> None:
427429
"""
428430
self.enabled = False
429431

430-
def __call__(self, func: Callable) -> Callable:
432+
def __call__(self, func: Callable[P, R]) -> Callable[P, R]:
431433
"""
432434
If the global profiler is enabled, decorate a function to start the
433435
profiler on function entry and stop it on function exit. Otherwise

0 commit comments

Comments
 (0)