1
1
"""Metrology APIs."""
2
2
3
- from typing import Final , Protocol , Self , override , runtime_checkable
3
+ from typing import Any , Final , Generic , Protocol , Self , TypeVar , override , runtime_checkable
4
4
5
5
import optype as op
6
6
7
7
__version__ : Final = "0.0.1.dev0"
8
8
__all__ = ["__version__" , "Dimension" , "Quantity" , "Unit" ]
9
9
10
10
11
+ VT = TypeVar ('VT' )
12
+ DT = TypeVar ('DT' , bound = 'Dimension' )
13
+ UT = TypeVar ('UT' , bound = 'Unit[DT]' )
14
+
11
15
@runtime_checkable
12
- class MetrologyNamespace [Q : Quantity [V , U , D ], V , U : Unit [D ], D : Dimension ](Protocol ):
16
+ class MetrologyNamespace [Q : Quantity [VT , UT , DT ], V , U : Unit [DT ], D : Dimension ](Protocol ):
13
17
14
18
@staticmethod
15
19
def asdimension (obj : str | D ) -> D : ...
@@ -23,9 +27,9 @@ def asquantity(obj: Q | V, *, unit: U) -> Q: ...
23
27
24
28
@runtime_checkable
25
29
class Dimension (Protocol ):
26
- def __metrology_namespace__ [Q : Quantity [V , U , Self ], V , U : Unit [Self ]](
30
+ def __metrology_namespace__ [Q : Quantity [VT , UT , DT ], V , U : Unit [DT ]](
27
31
self , / , * , api_version : str | None = None
28
- ) -> MetrologyNamespace [Q , U , Self ]:
32
+ ) -> MetrologyNamespace [Q , V , U , Self ]:
29
33
"""
30
34
Returns an object that has all the metrology API functions on it.
31
35
Parameters
@@ -48,9 +52,9 @@ def __rtruediv__(self, other: Self, /) -> Self: ...
48
52
49
53
@runtime_checkable
50
54
class Unit [D : Dimension ](Protocol ):
51
- def __metrology_namespace__ [Q : Quantity ](
55
+ def __metrology_namespace__ [Q : Quantity [ VT , UT , DT ], V ](
52
56
self , / , * , api_version : str | None = None
53
- ) -> MetrologyNamespace [Q , Self , D ]:
57
+ ) -> MetrologyNamespace [Q , V , Self , D ]:
54
58
"""
55
59
Returns an object that has all the metrology API functions on it.
56
60
Parameters
@@ -76,10 +80,10 @@ def __rpow__(self, other: int | float, /) -> Self: ...
76
80
77
81
78
82
@runtime_checkable
79
- class Quantity [V , U : Unit [D ], D : Dimension ](Protocol ):
83
+ class Quantity [V , U : Unit [DT ], D : Dimension ](Protocol ):
80
84
def __metrology_namespace__ (
81
85
self , / , * , api_version : str | None = None
82
- ) -> MetrologyNamespace [Self , U , D ]:
86
+ ) -> MetrologyNamespace [Self , V , U , D ]:
83
87
"""
84
88
Returns an object that has all the metrology API functions on it.
85
89
Parameters
0 commit comments