Skip to content

Commit 8d436bf

Browse files
andrewgsavagelucascolley
authored andcommitted
namespace
1 parent af9cca4 commit 8d436bf

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,8 +8,45 @@
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: ...
@@ -20,6 +57,21 @@ def __rtruediv__(self, other: Self, /) -> Self: ...
2057

2158
@runtime_checkable
2259
class Unit(Protocol):
60+
def __metrology_namespace__(
61+
self, /, *, api_version: str | None = None
62+
) -> MetrologyNamespace:
63+
"""
64+
Returns an object that has all the metrology API functions on it.
65+
Parameters
66+
----------
67+
api_version: str or None
68+
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``.
69+
Returns
70+
-------
71+
out: Any
72+
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.
73+
"""
74+
2375
@property
2476
def dimension(self) -> Dimension: ...
2577

@@ -31,8 +83,24 @@ def __rmul__(self, other: Self, /) -> Self: ...
3183
def __rtruediv__(self, other: Self, /) -> Self: ...
3284
def __rpow__(self, other: int | float, /) -> Self: ...
3385

86+
3487
@runtime_checkable
3588
class Quantity[V, U: Unit](Protocol):
89+
def __metrology_namespace__(
90+
self, /, *, api_version: str | None = None
91+
) -> MetrologyNamespace:
92+
"""
93+
Returns an object that has all the metrology API functions on it.
94+
Parameters
95+
----------
96+
api_version: str or None
97+
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``.
98+
Returns
99+
-------
100+
out: Any
101+
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.
102+
"""
103+
36104
@property
37105
def value(self) -> V: ...
38106
@property

0 commit comments

Comments
 (0)