Skip to content

Commit d208976

Browse files
committed
Simplify typing
1 parent 0b1a51e commit d208976

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

xarray/util/deprecation_helpers.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,9 @@
3434
import inspect
3535
import warnings
3636
from functools import wraps
37-
from typing import TYPE_CHECKING, Any, Callable, TypeVar
37+
from typing import Callable, TypeVar
3838

39-
if TYPE_CHECKING:
40-
from typing_extensions import ParamSpec
41-
42-
P = ParamSpec("P")
43-
R = TypeVar("R")
44-
else:
45-
P = Any
46-
R = Any
39+
from xarray.core.utils import emit_user_level_warning
4740

4841
T = TypeVar("T", bound=Callable)
4942

@@ -126,24 +119,26 @@ def inner(*args, **kwargs):
126119
return _decorator
127120

128121

129-
def deprecate_dims(func: Callable[P, R]) -> Callable[P, R]:
122+
def deprecate_dims(func: T) -> T:
130123
"""
131124
For functions that previously took `dims` as a kwarg, and have now transitioned to
132125
`dim`. This decorator will issue a warning if `dims` is passed while forwarding it
133126
to `dim`.
134127
"""
135128

136129
@wraps(func)
137-
def wrapper(*args: "P.args", **kwargs: "P.kwargs") -> R:
130+
def wrapper(*args, **kwargs):
138131
if "dims" in kwargs:
139-
warnings.warn(
132+
emit_user_level_warning(
140133
"The `dims` argument has been renamed to `dim`, and will be removed "
141-
"in the future. This is taking place throughout xarray.",
142-
# Upgrade to `DeprecationWarning` in the future
134+
"in the future. This renaming is taking place throughout xarray over the "
135+
"next few releases.",
136+
# Upgrade to `DeprecationWarning` in the future, when the renaming is complete.
143137
PendingDeprecationWarning,
144-
stacklevel=2,
145138
)
146139
kwargs["dim"] = kwargs.pop("dims")
147140
return func(*args, **kwargs)
148141

149-
return wrapper
142+
# We're quite confident we're just returning `T` from this function, so it's fine to ignore typing
143+
# within the function.
144+
return wrapper # type: ignore

0 commit comments

Comments
 (0)