-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MetrologyNamespace (initial PR) #9
base: main
Are you sure you want to change the base?
Conversation
out: Any | ||
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. | ||
""" | ||
|
||
def __mul__(self, other: Self, /) -> Self: ... | ||
def __truediv__(self, other: Self, /) -> Self: ... | ||
def __pow__(self, other: int, /) -> Self: ... | ||
|
||
|
||
@runtime_checkable | ||
class Unit(Protocol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we are suggesting here to parametrize Unit
with a D: Dimension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most libraries will have Dimension as only one class, but parametrizing like this allows for users/libraries to have different classes if they choose. Potential use cases include:
- Differentiating between base and composed dimensions (if they use different classes)
- Supporting different dimension classes, e.g greedy vs lazy resolution of the dimension
- Typing functions that can take a quantity from one library and convert it to a quantity of another library.
@property | ||
def Dimension(self) -> D: ... | ||
|
||
@property | ||
def Unit(self) -> U: ... | ||
|
||
@property | ||
def Quantity(self) -> Q: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we even need to make the classes accessible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. Like array api, which doesn't
def asdimension(obj: str | D) -> D: ... | ||
|
||
@staticmethod | ||
def asunit(obj) -> U[D]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def asunit(obj) -> U[D]: ... | |
def asunit(obj: str | U) -> U[D]: ... |
should this be type hinted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps #11 to consider
transferred from quantity-dev/quantity-api#5