File: _typing.py

package info (click to toggle)
python-pint 0.25.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,940 kB
  • sloc: python: 20,478; makefile: 148
file content (51 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations

from collections.abc import Callable
from decimal import Decimal
from fractions import Fraction
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union

from .compat import Never, TypeAlias

if TYPE_CHECKING:
    from .facets.plain import PlainQuantity as Quantity
    from .facets.plain import PlainUnit as Unit
    from .util import UnitsContainer


HAS_NUMPY = False
if TYPE_CHECKING:
    from .compat import HAS_NUMPY

if HAS_NUMPY:
    from .compat import np

    Scalar: TypeAlias = Union[complex, float, int, Decimal, Fraction, np.number[Any]]
    Array = np.ndarray[Any, Any]
else:
    Scalar: TypeAlias = Union[complex, float, int, Decimal, Fraction]
    Array: TypeAlias = Never

# TODO: Change when Python 3.10 becomes minimal version.
Magnitude = Union[Scalar, Array]

UnitLike = Union[str, dict[str, Scalar], "UnitsContainer", "Unit"]

QuantityOrUnitLike = Union["Quantity", UnitLike]

Shape = tuple[int, ...]

S = TypeVar("S")

FuncType = Callable[..., Any]
F = TypeVar("F", bound=FuncType)


# TODO: Improve or delete types
QuantityArgument = Any

T = TypeVar("T")


class Handler(Protocol):
    def __getitem__(self, item: type[T]) -> Callable[[T], None]: ...