Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pathspec/_typing.py: 86%
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"""
2This module provides stubs for type hints not supported by all relevant Python
3versions.
5NOTICE: This project should have zero required dependencies which means it
6cannot simply require :module:`typing_extensions`, and I do not want to maintain
7a vendored copy of :module:`typing_extensions`.
8"""
10import functools
11import warnings
12from typing import (
13 Any,
14 Callable, # Replaced by `collections.abc.Callable` in 3.9.2.
15 Optional, # Replaced by `X | None` in 3.10.
16 TypeVar)
17try:
18 from typing import AnyStr # Removed in 3.18.
19except ImportError:
20 AnyStr = TypeVar('AnyStr', str, bytes)
21try:
22 from typing import Never # Added in 3.11.
23except ImportError:
24 from typing import NoReturn as Never
26F = TypeVar('F', bound=Callable[..., Any])
28try:
29 from warnings import deprecated # Added in 3.13.
30except ImportError:
31 try:
32 from typing_extensions import deprecated
33 except ImportError:
34 def deprecated(
35 message: str,
36 /, *,
37 category: Optional[type[Warning]] = DeprecationWarning,
38 stacklevel: int = 1,
39 ) -> Callable[[F], F]:
40 def decorator(f: F) -> F:
41 @functools.wraps(f)
42 def wrapper(*a, **k):
43 warnings.warn(message, category=category, stacklevel=stacklevel+1)
44 return f(*a, **k)
45 return wrapper
46 return decorator
48try:
49 from typing import override # Added in 3.12.
50except ImportError:
51 try:
52 from typing_extensions import override
53 except ImportError:
54 def override(f: F) -> F:
55 return f
58def assert_unreachable(message: str) -> Never:
59 """
60 The code path is unreachable. Raises an :class:`AssertionError`.
62 *message* (:class:`str`) is the error message.
63 """
64 raise AssertionError(message)