Skip to content

Commit ee52381

Browse files
authored
Merge branch 'python-quantities:master' into trapz
2 parents e32259b + 224d8ca commit ee52381

3 files changed

Lines changed: 99 additions & 56 deletions

File tree

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,48 @@ jobs:
6767
run: |
6868
PY_IGNORE_IMPORTMISMATCH=1 pytest
6969
python -m doctest README.rst
70+
71+
type-check:
72+
runs-on: ${{ matrix.os }}
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
os: [ ubuntu-latest ]
77+
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
78+
numpy-version: [ "1.22", "1.23", "1.24" ]
79+
steps:
80+
- uses: actions/checkout@v2
81+
82+
- name: Set up Python ${{ matrix.python-version }}
83+
uses: actions/setup-python@v2
84+
with:
85+
python-version: ${{ matrix.python-version }}
86+
87+
- name: Get pip cache dir
88+
id: pip-cache
89+
run: |
90+
echo "::set-output name=dir::$(pip cache dir)"
91+
92+
- name: Cache
93+
uses: actions/cache@v2
94+
with:
95+
path: ${{ steps.pip-cache.outputs.dir }}
96+
key:
97+
${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.numpy-version }}-v1-${{ hashFiles('**/setup.py') }}
98+
restore-keys: |
99+
${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.numpy-version }}-v1-
100+
101+
- name: Install dependencies
102+
run: |
103+
python -m pip install -U pip
104+
python -m pip install -U wheel
105+
python -m pip install "numpy==${{ matrix.numpy-version }}"
106+
python -m pip install -U mypy
107+
108+
- name: Install
109+
run: |
110+
pip install .
111+
112+
- name: Check type information
113+
run: |
114+
mypy quantities

quantities/quantity.pyi

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from typing import Optional, Any
1+
from typing import Any, Optional
22

3-
from quantities.dimensionality import Dimensionality
4-
from quantities.typing.quantities import DimensionalityDescriptor, QuantityData
53
import numpy.typing as npt
64

5+
from quantities.dimensionality import Dimensionality
6+
from quantities.typing.quantities import DimensionalityDescriptor, QuantityData
77

88
def validate_unit_quantity(value: Quantity) -> Quantity:
99
...
@@ -23,8 +23,8 @@ def scale_other_units(f: Any) -> None:
2323

2424
class Quantity(npt.NDArray):
2525

26-
def __new__(cls, data: QuantityData, units: DimensionalityDescriptor = '',
27-
dtype: Optional[object] = None, copy: bool = True) -> Quantity: #type: ignore
26+
def __new__(cls, data: QuantityData, units: DimensionalityDescriptor = ...,
27+
dtype: Optional[object] = ..., copy: bool = ...) -> Quantity:
2828
...
2929

3030
@property
@@ -51,59 +51,54 @@ class Quantity(npt.NDArray):
5151
def units(self) -> Quantity:
5252
...
5353

54-
def rescale(self, units: Optional[DimensionalityDescriptor] = None) -> Quantity:
54+
def rescale(self, units: Optional[DimensionalityDescriptor] = ...) -> Quantity:
5555
...
5656

5757
def rescale_preferred(self) -> Quantity:
5858
...
5959

60-
def __add__(self, other) -> Quantity:
61-
...
60+
# numeric methods
61+
def __add__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
62+
def __radd__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
63+
def __iadd__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
6264

63-
def __radd__(self, other) -> Quantity:
64-
...
65+
def __sub__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
66+
def __rsub__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
67+
def __isub__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
6568

66-
def __iadd__(self, other) -> Quantity:
67-
...
69+
def __mul__(self, other) -> Quantity: ...
70+
def __rmul__(self, other) -> Quantity: ...
71+
def __imul__(self, other) -> Quantity: ...
6872

73+
# NOTE matmul is not supported
6974

70-
def __sub__(self, other) -> Quantity: # type: ignore[override]
71-
...
75+
def __truediv__(self, other) -> Quantity: ... # type: ignore[override]
76+
def __rtruediv__(self, other) -> Quantity: ... # type: ignore[override]
77+
def __itruediv__(self, other) -> Quantity: ... # type: ignore[override]
7278

79+
def __floordiv__(self, other) -> Quantity: ... # type: ignore[override]
80+
def __rfloordiv__(self, other) -> Quantity: ... # type: ignore[override]
81+
def __ifloordiv__(self, other) -> Quantity: ... # type: ignore[override]
7382

74-
def __rsub__(self, other) -> Quantity: # type: ignore[override]
75-
...
83+
def __mod__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
84+
def __rmod__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
85+
def __imod__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
7686

87+
# NOTE divmod is not supported
7788

78-
def __isub__(self, other) -> Quantity: # type: ignore[override]
79-
...
89+
def __pow__(self, power) -> Quantity: ...
90+
def __rpow__(self, power) -> Quantity: ...
91+
def __ipow__(self, power) -> Quantity: ...
8092

81-
def __mod__(self, other) -> Quantity:
82-
...
93+
# shift and bitwise are not supported
8394

84-
def __imod__(self, other) -> Quantity:
85-
...
86-
87-
# def __imul__(self, other):
88-
# ...
89-
90-
def __rmul__(self, other) -> Quantity:
91-
...
92-
93-
# def __itruediv__(self, other) :
94-
# ...
95-
96-
97-
def __rtruediv__(self, other) -> Quantity: # type: ignore[override]
98-
...
99-
100-
def __pow__(self, power) -> Quantity:
101-
...
102-
103-
def __ipow__(self, other) -> Quantity:
104-
...
95+
# unary methods
96+
def __neg__(self) -> Quantity: ...
97+
# def __pos__(self) -> Quantity: ... # GH#94
98+
def __abs__(self) -> Quantity: ...
99+
# NOTE invert is not supported
105100

106-
def __round__(self, decimals: int = 0) -> Quantity:
101+
def __round__(self, decimals: int = ...) -> Quantity:
107102
...
108103

109104
def __repr__(self) -> str:

quantities/unitquantity.pyi

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
from typing import Optional, Union, List, Any, overload
1+
from typing import Any, List, Optional, Union, overload
22

33
from quantities import Quantity
44
from quantities.dimensionality import Dimensionality
55

6-
76
class UnitQuantity(Quantity):
87
_primary_order: int
98
_secondary_order: int
109
_reference_quantity: Optional[Quantity]
1110

1211
def __new__(
13-
cls, name: str, definition: Optional[Union[Quantity, float, int]] = None, symbol: Optional[str] = None,
14-
u_symbol: Optional[str] = None,
15-
aliases: List[str] = [], doc=None
12+
cls, name: str, definition: Optional[Union[Quantity, float, int]] = ..., symbol: Optional[str] = ...,
13+
u_symbol: Optional[str] = ...,
14+
aliases: List[str] = ..., doc=...
1615
) -> UnitQuantity:
1716
...
1817

1918
def __init__(
20-
self, name: str, definition: Optional[Union[Quantity, float, int]] = None, symbol: Optional[str] = None,
21-
u_symbol: Optional[str] = None,
22-
aliases: List[str] = [], doc=None
19+
self, name: str, definition: Optional[Union[Quantity, float, int]] = ..., symbol: Optional[str] = ...,
20+
u_symbol: Optional[str] = ...,
21+
aliases: List[str] = ..., doc=...
2322
) -> None:
2423
...
2524

@@ -161,10 +160,14 @@ class UnitConstant(UnitQuantity):
161160
...
162161

163162

164-
def set_default_units(system: Optional[str], currency: Optional[Union[str, UnitCurrency]],
165-
current: Optional[Union[str, UnitCurrent]], information: Optional[Union[str, UnitInformation]],
166-
length: Optional[Union[str, UnitLength]],
167-
luminous_intensity: Optional[Union[str, UnitLuminousIntensity]],
168-
mass: Optional[Union[str, UnitMass]], substance: Optional[Union[str, UnitSubstance]],
169-
temperature: Optional[Union[str, UnitTemperature]], time: Optional[Union[str, UnitTime]]):
163+
def set_default_units(system: Optional[str] = ...,
164+
currency: Optional[Union[str, UnitCurrency]] = ...,
165+
current: Optional[Union[str, UnitCurrent]] = ...,
166+
information: Optional[Union[str, UnitInformation]] = ...,
167+
length: Optional[Union[str, UnitLength]] = ...,
168+
luminous_intensity: Optional[Union[str, UnitLuminousIntensity]] = ...,
169+
mass: Optional[Union[str, UnitMass]] = ...,
170+
substance: Optional[Union[str, UnitSubstance]] = ...,
171+
temperature: Optional[Union[str, UnitTemperature]] = ...,
172+
time: Optional[Union[str, UnitTime]] = ...):
170173
...

0 commit comments

Comments
 (0)