Skip to content

Commit 0b24532

Browse files
andrewgsavagelucascolley
authored andcommitted
namespace
1 parent f7bcae8 commit 0b24532

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: ...
@@ -23,6 +60,21 @@ def __ne__(self, other: Self, /) -> bool: ...
2360

2461
@runtime_checkable
2562
class Unit(Protocol):
63+
def __metrology_namespace__(
64+
self, /, *, api_version: str | None = None
65+
) -> MetrologyNamespace:
66+
"""
67+
Returns an object that has all the metrology API functions on it.
68+
Parameters
69+
----------
70+
api_version: str or None
71+
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``.
72+
Returns
73+
-------
74+
out: Any
75+
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.
76+
"""
77+
2678
@property
2779
def dimension(self) -> Dimension: ...
2880

@@ -34,8 +86,24 @@ def __rmul__(self, other: Self, /) -> Self: ...
3486
def __rtruediv__(self, other: Self, /) -> Self: ...
3587
def __rpow__(self, other: int | float, /) -> Self: ...
3688

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

0 commit comments

Comments
 (0)