Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

initial Unit protocol #1

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SCM syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# pixi environments
.pixi
*.egg-info
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[project]
authors = [{ name = "quantity-dev contributors" }]
dependencies = []
name = "unit-api"
requires-python = ">= 3.12"
version = "0.0.1.dev0"

[build-system]
build-backend = "hatchling.build"
requires = ["hatchling"]

[tool.pixi.project]
channels = ["https://prefix.dev/conda-forge"]
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"]

[tool.pixi.pypi-dependencies]
unit_api = { path = ".", editable = true }
22 changes: 22 additions & 0 deletions src/unit_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Unit API."""

from typing import Any, Final, Protocol, Self, runtime_checkable

__version__: Final = "0.0.1.dev0"
__all__ = ["__version__", "Unit"]

type Dimension = Any # TODO: dimension-api
type Quantity = Any # TODO: quantity-api

@runtime_checkable
class Unit(Protocol):
@property
def dimension(self) -> Dimension: ...

def __mul__(self, other: Self, /) -> Self: ...
Copy link

Choose a reason for hiding this comment

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

We also need the reflected operators, right?

def __truediv__(self, other: Self, /) -> Self: ...
def __pow__(self, other: int | float, /) -> Self: ...

def __rmul__(self, other: Self, /) -> Self: ...
def __rtruediv__(self, other: Self, /) -> Self: ...
def __rpow__(self, other: int | float, /) -> Self: ...