Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/dulwich/__init__.py: 37%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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#
23"""Python implementation of the Git file formats and protocols."""
25from collections.abc import Callable
26from typing import TYPE_CHECKING, Any, ParamSpec, TypeVar
28__version__ = (1, 1, 0)
30__all__ = ["__version__", "replace_me"]
32P = ParamSpec("P")
33R = TypeVar("R")
34F = TypeVar("F", bound=Callable[..., Any])
36if TYPE_CHECKING:
37 # For type checking, always use our typed signature
38 def replace_me(
39 since: tuple[int, ...] | str | None = None,
40 remove_in: tuple[int, ...] | str | None = None,
41 ) -> Callable[[Callable[P, R]], Callable[P, R]]:
42 """Decorator to mark functions as deprecated."""
43 ...
45else:
46 try:
47 from dissolve import replace_me as replace_me
48 except ImportError:
49 # if dissolve is not installed, then just provide a basic implementation
50 # of its replace_me decorator
51 def replace_me(
52 since: tuple[int, ...] | str | None = None,
53 remove_in: tuple[int, ...] | str | None = None,
54 ) -> Callable[[Callable[P, R]], Callable[P, R]]:
55 """Decorator to mark functions as deprecated.
57 Args:
58 since: Version when the function was deprecated
59 remove_in: Version when the function will be removed
61 Returns:
62 Decorator function
63 """
65 def decorator(func: Callable[P, R]) -> Callable[P, R]:
66 import functools
67 import warnings
69 m = f"{func.__name__} is deprecated"
70 since_str = str(since) if since is not None else None
71 remove_in_str = str(remove_in) if remove_in is not None else None
73 if since_str is not None and remove_in_str is not None:
74 m += f" since {since_str} and will be removed in {remove_in_str}"
75 elif since_str is not None:
76 m += f" since {since_str}"
77 elif remove_in_str is not None:
78 m += f" and will be removed in {remove_in_str}"
79 else:
80 m += " and will be removed in a future version"
82 @functools.wraps(func)
83 def _wrapped_func(*args: P.args, **kwargs: P.kwargs) -> R:
84 warnings.warn(
85 m,
86 DeprecationWarning,
87 stacklevel=2,
88 )
89 return func(*args, **kwargs)
91 return _wrapped_func
93 return decorator