From 890c0c5c69509214b0b549ea4a39ce722b01c382 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Wed, 5 Feb 2025 15:03:06 +0000 Subject: [PATCH 1/5] initial `Dimension` protocol --- .gitattributes | 2 ++ .gitignore | 4 ++++ pyproject.toml | 17 +++++++++++++++++ src/dimension_api/__init__.py | 13 +++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 pyproject.toml create mode 100644 src/dimension_api/__init__.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8f61a8e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# SCM syntax highlighting +pixi.lock linguist-language=YAML linguist-generated=true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..740bb7d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +# pixi environments +.pixi +*.egg-info diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ae9bcf6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[project] +authors = [{ name = "quantity-dev contributors" }] +dependencies = [] +name = "dimension-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] +dimension_api = { path = ".", editable = true } diff --git a/src/dimension_api/__init__.py b/src/dimension_api/__init__.py new file mode 100644 index 0000000..cb2fa50 --- /dev/null +++ b/src/dimension_api/__init__.py @@ -0,0 +1,13 @@ +"""Dimension API.""" + +from typing import Protocol, Self, runtime_checkable + +__version__ = "0.0.1.dev0" +__all__ = ["Dimension"] + +@runtime_checkable +class Dimension(Protocol): + def __eq__(self, other: Self, /) -> bool: ... + def __mul__(self, other: Self, /) -> Self: ... + def __div__(self, other: Self, /) -> Self: ... + def __pow__(self, other: int, /) -> Self: ... From e8e35f28476378b976006947c8ac2fe51ae77b26 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Wed, 5 Feb 2025 15:21:21 +0000 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Joren Hammudoglu --- src/dimension_api/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dimension_api/__init__.py b/src/dimension_api/__init__.py index cb2fa50..90f176d 100644 --- a/src/dimension_api/__init__.py +++ b/src/dimension_api/__init__.py @@ -1,13 +1,13 @@ """Dimension API.""" -from typing import Protocol, Self, runtime_checkable +from typing import Final, Protocol, Self, runtime_checkable -__version__ = "0.0.1.dev0" -__all__ = ["Dimension"] +__version__: Final = "0.0.1.dev0" +__all__ = ["__version__", "Dimension"] @runtime_checkable class Dimension(Protocol): def __eq__(self, other: Self, /) -> bool: ... def __mul__(self, other: Self, /) -> Self: ... - def __div__(self, other: Self, /) -> Self: ... + def __truediv__(self, other: Self, /) -> Self: ... def __pow__(self, other: int, /) -> Self: ... From 9d54f1c9d798e35b94cc14e606ccd6797530582d Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Wed, 5 Feb 2025 15:23:38 +0000 Subject: [PATCH 3/5] remove `__eq__` --- src/dimension_api/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dimension_api/__init__.py b/src/dimension_api/__init__.py index 90f176d..0885dc2 100644 --- a/src/dimension_api/__init__.py +++ b/src/dimension_api/__init__.py @@ -7,7 +7,6 @@ @runtime_checkable class Dimension(Protocol): - def __eq__(self, other: Self, /) -> bool: ... def __mul__(self, other: Self, /) -> Self: ... def __truediv__(self, other: Self, /) -> Self: ... def __pow__(self, other: int, /) -> Self: ... From 0cd533e6119a0e57528d4c7fc9bcf46b0dfbedff Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Thu, 6 Feb 2025 10:16:06 +0000 Subject: [PATCH 4/5] add is_dimensionless --- src/dimension_api/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dimension_api/__init__.py b/src/dimension_api/__init__.py index 0885dc2..6ad8eb9 100644 --- a/src/dimension_api/__init__.py +++ b/src/dimension_api/__init__.py @@ -7,6 +7,9 @@ @runtime_checkable class Dimension(Protocol): + @property + def is_dimensionless(self) -> bool: ... + def __mul__(self, other: Self, /) -> Self: ... def __truediv__(self, other: Self, /) -> Self: ... def __pow__(self, other: int, /) -> Self: ... From fbb9e140a8117bcdc665e04284c33c4a0c6a3260 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Sat, 8 Feb 2025 21:23:42 +0000 Subject: [PATCH 5/5] remove is_dimensionless --- src/dimension_api/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/dimension_api/__init__.py b/src/dimension_api/__init__.py index 6ad8eb9..0885dc2 100644 --- a/src/dimension_api/__init__.py +++ b/src/dimension_api/__init__.py @@ -7,9 +7,6 @@ @runtime_checkable class Dimension(Protocol): - @property - def is_dimensionless(self) -> bool: ... - def __mul__(self, other: Self, /) -> Self: ... def __truediv__(self, other: Self, /) -> Self: ... def __pow__(self, other: int, /) -> Self: ...