__init__.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # __init__.py -- The git module of dulwich
  2. # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
  3. # Copyright (C) 2008 Jelmer Vernooij <jelmer@jelmer.uk>
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  6. # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
  7. # General Public License as published by the Free Software Foundation; version 2.0
  8. # or (at your option) any later version. You can redistribute it and/or
  9. # modify it under the terms of either of these two licenses.
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # You should have received a copy of the licenses; if not, see
  18. # <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
  19. # and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
  20. # License, Version 2.0.
  21. #
  22. """Python implementation of the Git file formats and protocols."""
  23. from collections.abc import Callable
  24. from typing import TYPE_CHECKING, Any, ParamSpec, TypeVar
  25. __version__ = (0, 25, 0)
  26. __all__ = ["__version__", "replace_me"]
  27. P = ParamSpec("P")
  28. R = TypeVar("R")
  29. F = TypeVar("F", bound=Callable[..., Any])
  30. if TYPE_CHECKING:
  31. # For type checking, always use our typed signature
  32. def replace_me(
  33. since: tuple[int, ...] | str | None = None,
  34. remove_in: tuple[int, ...] | str | None = None,
  35. ) -> Callable[[Callable[P, R]], Callable[P, R]]:
  36. """Decorator to mark functions as deprecated."""
  37. ...
  38. else:
  39. try:
  40. from dissolve import replace_me as replace_me
  41. except ImportError:
  42. # if dissolve is not installed, then just provide a basic implementation
  43. # of its replace_me decorator
  44. def replace_me(
  45. since: tuple[int, ...] | str | None = None,
  46. remove_in: tuple[int, ...] | str | None = None,
  47. ) -> Callable[[Callable[P, R]], Callable[P, R]]:
  48. """Decorator to mark functions as deprecated.
  49. Args:
  50. since: Version when the function was deprecated
  51. remove_in: Version when the function will be removed
  52. Returns:
  53. Decorator function
  54. """
  55. def decorator(func: Callable[P, R]) -> Callable[P, R]:
  56. import functools
  57. import warnings
  58. m = f"{func.__name__} is deprecated"
  59. since_str = str(since) if since is not None else None
  60. remove_in_str = str(remove_in) if remove_in is not None else None
  61. if since_str is not None and remove_in_str is not None:
  62. m += f" since {since_str} and will be removed in {remove_in_str}"
  63. elif since_str is not None:
  64. m += f" since {since_str}"
  65. elif remove_in_str is not None:
  66. m += f" and will be removed in {remove_in_str}"
  67. else:
  68. m += " and will be removed in a future version"
  69. @functools.wraps(func)
  70. def _wrapped_func(*args: P.args, **kwargs: P.kwargs) -> R:
  71. warnings.warn(
  72. m,
  73. DeprecationWarning,
  74. stacklevel=2,
  75. )
  76. return func(*args, **kwargs)
  77. return _wrapped_func
  78. return decorator