|
34 | 34 | import inspect
|
35 | 35 | import warnings
|
36 | 36 | from functools import wraps
|
37 |
| -from typing import TYPE_CHECKING, Any, Callable, TypeVar |
| 37 | +from typing import Callable, TypeVar |
38 | 38 |
|
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 |
47 | 40 |
|
48 | 41 | T = TypeVar("T", bound=Callable)
|
49 | 42 |
|
@@ -126,24 +119,26 @@ def inner(*args, **kwargs):
|
126 | 119 | return _decorator
|
127 | 120 |
|
128 | 121 |
|
129 |
| -def deprecate_dims(func: Callable[P, R]) -> Callable[P, R]: |
| 122 | +def deprecate_dims(func: T) -> T: |
130 | 123 | """
|
131 | 124 | For functions that previously took `dims` as a kwarg, and have now transitioned to
|
132 | 125 | `dim`. This decorator will issue a warning if `dims` is passed while forwarding it
|
133 | 126 | to `dim`.
|
134 | 127 | """
|
135 | 128 |
|
136 | 129 | @wraps(func)
|
137 |
| - def wrapper(*args: "P.args", **kwargs: "P.kwargs") -> R: |
| 130 | + def wrapper(*args, **kwargs): |
138 | 131 | if "dims" in kwargs:
|
139 |
| - warnings.warn( |
| 132 | + emit_user_level_warning( |
140 | 133 | "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. |
143 | 137 | PendingDeprecationWarning,
|
144 |
| - stacklevel=2, |
145 | 138 | )
|
146 | 139 | kwargs["dim"] = kwargs.pop("dims")
|
147 | 140 | return func(*args, **kwargs)
|
148 | 141 |
|
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