Skip to content

Commit 0a01a42

Browse files
committed
typevars
1 parent 84e2c2c commit 0a01a42

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

pixi.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ python_version = "3.13"
4747
warn_unused_configs = true
4848
strict = true
4949
enable_error_code = ["ignore-without-code", "truthy-bool"]
50+
disable_error_code = ["explicit-any", "decorated-any"]
51+
# disallow_any_expr = false
5052

5153

5254
[tool.basedpyright]

src/metrology_apis/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
"""Metrology APIs."""
22

3-
from typing import Final, Protocol, Self, override, runtime_checkable
3+
from typing import Any, Final, Generic, Protocol, Self, TypeVar, override, runtime_checkable
44

55
import optype as op
66

77
__version__: Final = "0.0.1.dev0"
88
__all__ = ["__version__", "Dimension", "Quantity", "Unit"]
99

1010

11+
VT = TypeVar('VT')
12+
DT = TypeVar('DT', bound='Dimension')
13+
UT = TypeVar('UT', bound='Unit[DT]')
14+
1115
@runtime_checkable
12-
class MetrologyNamespace[Q: Quantity[V, U, D], V, U: Unit[D], D: Dimension](Protocol):
16+
class MetrologyNamespace[Q: Quantity[VT, UT, DT], V, U: Unit[DT], D: Dimension](Protocol):
1317

1418
@staticmethod
1519
def asdimension(obj: str | D) -> D: ...
@@ -23,9 +27,9 @@ def asquantity(obj: Q | V, *, unit: U) -> Q: ...
2327

2428
@runtime_checkable
2529
class Dimension(Protocol):
26-
def __metrology_namespace__[Q: Quantity[V, U, Self], V, U: Unit[Self]](
30+
def __metrology_namespace__[Q: Quantity[VT, UT, DT], V, U: Unit[DT]](
2731
self, /, *, api_version: str | None = None
28-
) -> MetrologyNamespace[Q, U, Self]:
32+
) -> MetrologyNamespace[Q, V, U, Self]:
2933
"""
3034
Returns an object that has all the metrology API functions on it.
3135
Parameters
@@ -48,9 +52,9 @@ def __rtruediv__(self, other: Self, /) -> Self: ...
4852

4953
@runtime_checkable
5054
class Unit[D: Dimension](Protocol):
51-
def __metrology_namespace__[Q: Quantity](
55+
def __metrology_namespace__[Q: Quantity[VT, UT, DT], V](
5256
self, /, *, api_version: str | None = None
53-
) -> MetrologyNamespace[Q, Self, D]:
57+
) -> MetrologyNamespace[Q, V, Self, D]:
5458
"""
5559
Returns an object that has all the metrology API functions on it.
5660
Parameters
@@ -76,10 +80,10 @@ def __rpow__(self, other: int | float, /) -> Self: ...
7680

7781

7882
@runtime_checkable
79-
class Quantity[V, U: Unit[D], D: Dimension](Protocol):
83+
class Quantity[V, U: Unit[DT], D: Dimension](Protocol):
8084
def __metrology_namespace__(
8185
self, /, *, api_version: str | None = None
82-
) -> MetrologyNamespace[Self, U, D]:
86+
) -> MetrologyNamespace[Self, V, U, D]:
8387
"""
8488
Returns an object that has all the metrology API functions on it.
8589
Parameters

0 commit comments

Comments
 (0)