Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andrewgsavage
Copy link

transferred from quantity-dev/quantity-api#5

@lucascolley lucascolley changed the title namespace MetrologyNamespace (initial PR) Mar 17, 2025
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):
Copy link
Member

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

Copy link

@nstarman nstarman Mar 17, 2025

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:

  1. Differentiating between base and composed dimensions (if they use different classes)
  2. Supporting different dimension classes, e.g greedy vs lazy resolution of the dimension
  3. Typing functions that can take a quantity from one library and convert it to a quantity of another library.

Comment on lines +23 to +30
@property
def Dimension(self) -> D: ...

@property
def Unit(self) -> U: ...

@property
def Quantity(self) -> Q: ...
Copy link
Member

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?

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]: ...
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def asunit(obj) -> U[D]: ...
def asunit(obj: str | U) -> U[D]: ...

should this be type hinted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps #11 to consider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants