Skip to content

Commit 9394d72

Browse files
committed
typevars
1 parent f4fa6e6 commit 9394d72

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ python_version = "3.13"
5555
warn_unused_configs = true
5656
strict = true
5757
enable_error_code = ["ignore-without-code", "truthy-bool"]
58+
disable_error_code = ["explicit-any", "decorated-any"]
59+
# disallow_any_expr = false
5860

5961

6062
[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 __rtruediv__(self, other: Self, /) -> 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)