Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typing] Fix type stubs #220

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 37 additions & 42 deletions quantities/quantity.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Optional, Any
from typing import Any, Optional

from quantities.dimensionality import Dimensionality
from quantities.typing.quantities import DimensionalityDescriptor, QuantityData
import numpy.typing as npt

from quantities.dimensionality import Dimensionality
from quantities.typing.quantities import DimensionalityDescriptor, QuantityData

def validate_unit_quantity(value: Quantity) -> Quantity:
...
Expand All @@ -23,8 +23,8 @@ def scale_other_units(f: Any) -> None:

class Quantity(npt.NDArray):

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

@property
Expand All @@ -51,59 +51,54 @@ class Quantity(npt.NDArray):
def units(self) -> Quantity:
...

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

def rescale_preferred(self) -> Quantity:
...

def __add__(self, other) -> Quantity:
...
# numeric methods
def __add__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
def __radd__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
def __iadd__(self, other: Quantity) -> Quantity: ... # type: ignore[override]

def __radd__(self, other) -> Quantity:
...
def __sub__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
def __rsub__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
def __isub__(self, other: Quantity) -> Quantity: ... # type: ignore[override]

def __iadd__(self, other) -> Quantity:
...
def __mul__(self, other) -> Quantity: ...
def __rmul__(self, other) -> Quantity: ...
def __imul__(self, other) -> Quantity: ...

# NOTE matmul is not supported

def __sub__(self, other) -> Quantity: # type: ignore[override]
...
def __truediv__(self, other) -> Quantity: ... # type: ignore[override]
def __rtruediv__(self, other) -> Quantity: ... # type: ignore[override]
def __itruediv__(self, other) -> Quantity: ... # type: ignore[override]

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

def __rsub__(self, other) -> Quantity: # type: ignore[override]
...
def __mod__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
def __rmod__(self, other: Quantity) -> Quantity: ... # type: ignore[override]
def __imod__(self, other: Quantity) -> Quantity: ... # type: ignore[override]

# NOTE divmod is not supported

def __isub__(self, other) -> Quantity: # type: ignore[override]
...
def __pow__(self, power) -> Quantity: ...
def __rpow__(self, power) -> Quantity: ...
def __ipow__(self, power) -> Quantity: ...

def __mod__(self, other) -> Quantity:
...
# shift and bitwise are not supported

def __imod__(self, other) -> Quantity:
...

# def __imul__(self, other):
# ...

def __rmul__(self, other) -> Quantity:
...

# def __itruediv__(self, other) :
# ...


def __rtruediv__(self, other) -> Quantity: # type: ignore[override]
...

def __pow__(self, power) -> Quantity:
...

def __ipow__(self, other) -> Quantity:
...
# unary methods
def __neg__(self) -> Quantity: ...
# def __pos__(self) -> Quantity: ... # GH#94
def __abs__(self) -> Quantity: ...
# NOTE invert is not supported

def __round__(self, decimals: int = 0) -> Quantity:
def __round__(self, decimals: int = ...) -> Quantity:
...

def __repr__(self) -> str:
Expand Down
31 changes: 17 additions & 14 deletions quantities/unitquantity.pyi
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
from typing import Optional, Union, List, Any, overload
from typing import Any, List, Optional, Union, overload

from quantities import Quantity
from quantities.dimensionality import Dimensionality


class UnitQuantity(Quantity):
_primary_order: int
_secondary_order: int
_reference_quantity: Optional[Quantity]

def __new__(
cls, name: str, definition: Optional[Union[Quantity, float, int]] = None, symbol: Optional[str] = None,
u_symbol: Optional[str] = None,
aliases: List[str] = [], doc=None
cls, name: str, definition: Optional[Union[Quantity, float, int]] = ..., symbol: Optional[str] = ...,
u_symbol: Optional[str] = ...,
aliases: List[str] = ..., doc=...
) -> UnitQuantity:
...

def __init__(
self, name: str, definition: Optional[Union[Quantity, float, int]] = None, symbol: Optional[str] = None,
u_symbol: Optional[str] = None,
aliases: List[str] = [], doc=None
self, name: str, definition: Optional[Union[Quantity, float, int]] = ..., symbol: Optional[str] = ...,
u_symbol: Optional[str] = ...,
aliases: List[str] = ..., doc=...
) -> None:
...

Expand Down Expand Up @@ -161,10 +160,14 @@ class UnitConstant(UnitQuantity):
...


def set_default_units(system: Optional[str], currency: Optional[Union[str, UnitCurrency]],
current: Optional[Union[str, UnitCurrent]], information: Optional[Union[str, UnitInformation]],
length: Optional[Union[str, UnitLength]],
luminous_intensity: Optional[Union[str, UnitLuminousIntensity]],
mass: Optional[Union[str, UnitMass]], substance: Optional[Union[str, UnitSubstance]],
temperature: Optional[Union[str, UnitTemperature]], time: Optional[Union[str, UnitTime]]):
def set_default_units(system: Optional[str] = ...,
currency: Optional[Union[str, UnitCurrency]] = ...,
current: Optional[Union[str, UnitCurrent]] = ...,
information: Optional[Union[str, UnitInformation]] = ...,
length: Optional[Union[str, UnitLength]] = ...,
luminous_intensity: Optional[Union[str, UnitLuminousIntensity]] = ...,
mass: Optional[Union[str, UnitMass]] = ...,
substance: Optional[Union[str, UnitSubstance]] = ...,
temperature: Optional[Union[str, UnitTemperature]] = ...,
time: Optional[Union[str, UnitTime]] = ...):
...