Skip to content

Commit de4c546

Browse files
committed
namespace
1 parent 6132413 commit de4c546

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/metrology_apis/__init__.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,67 @@
88
__all__ = ["__version__", "Dimension", "Quantity", "Unit"]
99

1010

11+
@runtime_checkable
12+
class MetrologyNamespace[Q: Quantity, U: Unit, D: Dimension](Protocol):
13+
14+
@staticmethod
15+
def asdimension(obj: str | D) -> D: ...
16+
17+
@staticmethod
18+
def asunit(obj) -> U[D]: ...
19+
20+
@staticmethod
21+
def asquantity(obj: V, unit: obj) -> Q[V, U[D]]: ...
22+
23+
@property
24+
def Dimension(self) -> D: ...
25+
26+
@property
27+
def Unit(self) -> U: ...
28+
29+
@property
30+
def Quantity(self) -> Q: ...
31+
32+
1133
@runtime_checkable
1234
class Dimension(Protocol):
35+
def __metrology_namespace__(
36+
self, /, *, api_version: str | None = None
37+
) -> MetrologyNamespace:
38+
"""
39+
Returns an object that has all the metrology API functions on it.
40+
Parameters
41+
----------
42+
api_version: str or None
43+
string representing the version of the metrology API specification to be returned. If it is ``None``, it should return the namespace corresponding to latest version of the metrology API specification. If the given version is invalid or not implemented for the given module, an error should be raised. Default: ``None``.
44+
Returns
45+
-------
46+
out: Any
47+
an object representing the metrology API namespace. It should have every top-level function defined in the specification as an attribute. It may contain other public names as well, but it is recommended to only include those names that are part of the specification.
48+
"""
49+
1350
def __mul__(self, other: Self, /) -> Self: ...
1451
def __truediv__(self, other: Self, /) -> Self: ...
1552
def __pow__(self, other: int, /) -> Self: ...
1653

1754

1855
@runtime_checkable
1956
class Unit(Protocol):
57+
def __metrology_namespace__(
58+
self, /, *, api_version: str | None = None
59+
) -> MetrologyNamespace:
60+
"""
61+
Returns an object that has all the metrology API functions on it.
62+
Parameters
63+
----------
64+
api_version: str or None
65+
string representing the version of the metrology API specification to be returned. If it is ``None``, it should return the namespace corresponding to latest version of the metrology API specification. If the given version is invalid or not implemented for the given module, an error should be raised. Default: ``None``.
66+
Returns
67+
-------
68+
out: Any
69+
an object representing the metrology API namespace. It should have every top-level function defined in the specification as an attribute. It may contain other public names as well, but it is recommended to only include those names that are part of the specification.
70+
"""
71+
2072
@property
2173
def dimension(self) -> Dimension: ...
2274

@@ -28,8 +80,24 @@ def __rmul__(self, other: Self, /) -> Self: ...
2880
def __rtruediv__(self, other: Self, /) -> Self: ...
2981
def __rpow__(self, other: int | float, /) -> Self: ...
3082

83+
3184
@runtime_checkable
3285
class Quantity[V, U: Unit](Protocol):
86+
def __metrology_namespace__(
87+
self, /, *, api_version: str | None = None
88+
) -> MetrologyNamespace:
89+
"""
90+
Returns an object that has all the metrology API functions on it.
91+
Parameters
92+
----------
93+
api_version: str or None
94+
string representing the version of the metrology API specification to be returned. If it is ``None``, it should return the namespace corresponding to latest version of the metrology API specification. If the given version is invalid or not implemented for the given module, an error should be raised. Default: ``None``.
95+
Returns
96+
-------
97+
out: Any
98+
an object representing the metrology API namespace. It should have every top-level function defined in the specification as an attribute. It may contain other public names as well, but it is recommended to only include those names that are part of the specification.
99+
"""
100+
33101
@property
34102
def value(self) -> V: ...
35103
@property

0 commit comments

Comments
 (0)