mirror of https://github.com/zulip/zulip.git
mypy: Improve typing to profile.py & remove FuncT from decorator.py.
FuncT was unused in decorator.py, and only imported into profile.py. The @profiled decorator is now more strongly typed on return-type. Annotations were converted to python3 format.
This commit is contained in:
parent
1cc0a3cc67
commit
0781237b1f
|
@ -43,7 +43,6 @@ else:
|
|||
get_remote_server_by_uuid = Mock()
|
||||
RemoteZulipServer = Mock() # type: ignore # https://github.com/JukkaL/mypy/issues/1188
|
||||
|
||||
FuncT = TypeVar('FuncT', bound=Callable[..., Any])
|
||||
ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse])
|
||||
ReturnT = TypeVar('ReturnT')
|
||||
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
import cProfile
|
||||
|
||||
from functools import wraps
|
||||
from typing import Any
|
||||
from typing import Any, TypeVar, Callable
|
||||
|
||||
from zerver.decorator import FuncT
|
||||
ReturnT = TypeVar('ReturnT')
|
||||
|
||||
def profiled(func):
|
||||
# type: (FuncT) -> FuncT
|
||||
def profiled(func: Callable[..., ReturnT]) -> Callable[..., ReturnT]:
|
||||
"""
|
||||
This decorator should obviously be used only in a dev environment.
|
||||
It works best when surrounding a function that you expect to be
|
||||
|
@ -25,11 +24,10 @@ def profiled(func):
|
|||
|
||||
"""
|
||||
@wraps(func)
|
||||
def wrapped_func(*args, **kwargs):
|
||||
# type: (*Any, **Any) -> Any
|
||||
def wrapped_func(*args: Any, **kwargs: Any) -> ReturnT:
|
||||
fn = func.__name__ + ".profile"
|
||||
prof = cProfile.Profile()
|
||||
retval = prof.runcall(func, *args, **kwargs) # type: Any
|
||||
retval = prof.runcall(func, *args, **kwargs) # type: ReturnT
|
||||
prof.dump_stats(fn)
|
||||
return retval
|
||||
return wrapped_func # type: ignore # https://github.com/python/mypy/issues/1927
|
||||
return wrapped_func
|
||||
|
|
Loading…
Reference in New Issue