Skip to content

Commit 161eaf5

Browse files
committed
updated deprecate_kwarg() so that PyCharm can correctly handle the returned type of the decorated function (issue #864)
1 parent de26ad2 commit 161eaf5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

larray/util/misc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import numpy as np
1818
import pandas as pd
1919

20+
from larray.util.types import R
21+
from typing import Callable
22+
2023
try:
2124
np.set_printoptions(legacy='1.13')
2225
except TypeError:
@@ -645,9 +648,9 @@ def deprecate_kwarg(old_arg_name, new_arg_name, mapping=None, arg_converter=None
645648
if mapping is not None and not isinstance(mapping, dict):
646649
raise TypeError("mapping from old to new argument values must be dict!")
647650

648-
def _deprecate_kwarg(func):
651+
def _deprecate_kwarg(func: Callable[..., R]) -> Callable[..., R]:
649652
@wraps(func)
650-
def wrapper(*args, **kwargs):
653+
def wrapper(*args, **kwargs) -> R:
651654
old_arg_value = kwargs.pop(old_arg_name, None)
652655
if old_arg_value is not None:
653656
if mapping is not None:

larray/util/types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Union
1+
from typing import Union, TypeVar
22
from numpy import generic
33

4+
R = TypeVar('R')
5+
46
Scalar = Union[bool, int, float, str, bytes, generic]

0 commit comments

Comments
 (0)