|
|
@@ -24,7 +24,7 @@
|
|
|
"""Python implementation of the Git file formats and protocols."""
|
|
|
|
|
|
import sys
|
|
|
-from typing import Callable, Optional, TypeVar
|
|
|
+from typing import Optional, TypeVar, Union
|
|
|
|
|
|
if sys.version_info >= (3, 10):
|
|
|
from typing import ParamSpec
|
|
|
@@ -37,6 +37,7 @@ __all__ = ["__version__", "replace_me"]
|
|
|
|
|
|
P = ParamSpec("P")
|
|
|
R = TypeVar("R")
|
|
|
+F = TypeVar("F")
|
|
|
|
|
|
try:
|
|
|
from dissolve import replace_me
|
|
|
@@ -44,24 +45,28 @@ except ImportError:
|
|
|
# if dissolve is not installed, then just provide a basic implementation
|
|
|
# of its replace_me decorator
|
|
|
def replace_me(
|
|
|
- since: Optional[str] = None, remove_in: Optional[str] = None
|
|
|
- ) -> Callable[[Callable[P, R]], Callable[P, R]]:
|
|
|
- def decorator(func: Callable[P, R]) -> Callable[P, R]:
|
|
|
+ since: Optional[Union[str, tuple[int, ...]]] = None,
|
|
|
+ remove_in: Optional[Union[str, tuple[int, ...]]] = None
|
|
|
+ ):
|
|
|
+ def decorator(func):
|
|
|
import functools
|
|
|
import warnings
|
|
|
|
|
|
m = f"{func.__name__} is deprecated"
|
|
|
- if since is not None and remove_in is not None:
|
|
|
- m += f" since {since} and will be removed in {remove_in}"
|
|
|
- elif since is not None:
|
|
|
- m += f" since {since}"
|
|
|
- elif remove_in is not None:
|
|
|
- m += f" and will be removed in {remove_in}"
|
|
|
+ since_str = str(since) if since is not None else None
|
|
|
+ remove_in_str = str(remove_in) if remove_in is not None else None
|
|
|
+
|
|
|
+ if since_str is not None and remove_in_str is not None:
|
|
|
+ m += f" since {since_str} and will be removed in {remove_in_str}"
|
|
|
+ elif since_str is not None:
|
|
|
+ m += f" since {since_str}"
|
|
|
+ elif remove_in_str is not None:
|
|
|
+ m += f" and will be removed in {remove_in_str}"
|
|
|
else:
|
|
|
m += " and will be removed in a future version"
|
|
|
|
|
|
@functools.wraps(func)
|
|
|
- def _wrapped_func(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
|
+ def _wrapped_func(*args, **kwargs):
|
|
|
warnings.warn(
|
|
|
m,
|
|
|
DeprecationWarning,
|