Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black
args: [--safe, --quiet]
Expand Down
11 changes: 4 additions & 7 deletions src/barril/basic/fraction/_fraction_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def GetLocalizedString(self) -> str:
"""
from barril.basic.format_float import FormatFloat

return self.__FormatToString(FormatFloat) # type:ignore[arg-type]
return self.__FormatToString(FormatFloat) # type: ignore[arg-type]

def GetLocalizedFraction(self) -> str:
"""
Expand All @@ -123,7 +123,7 @@ def GetLocalizedFraction(self) -> str:
"""
from barril.basic.format_float import FormatFloat

return self.__FormatFractionToString(FormatFloat) # type:ignore[arg-type]
return self.__FormatFractionToString(FormatFloat) # type: ignore[arg-type]

def __str__(self) -> str:
"""
Expand Down Expand Up @@ -263,16 +263,13 @@ def __copy__(self) -> "FractionValue":
[-+]?\d+(?:(\.|\,)\d+) # number, float, accepting "." or ",".
"""

FRACTION_PART_EXPR = (
r"""
FRACTION_PART_EXPR = r"""
(?:
(?P<numerator>%s?) # numerator
\s*/\s* # '/' no matter if exist spaces
(?P<denominator>\d+) # only integers
)?
"""
% NUMBER_EXPR
)
""" % NUMBER_EXPR

FRACTION_COMPLETE_EXPR = r"""
(?P<float>{}?) # The whole number
Expand Down
16 changes: 8 additions & 8 deletions src/barril/basic/fraction/_tests/test_fraction_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def testBasicUsage() -> None:
assert f.fraction == Fraction(6, 5)

with pytest.raises(TypeError):
f.SetNumber("hello") # type:ignore[arg-type]
f.SetNumber("hello") # type: ignore[arg-type]
with pytest.raises(TypeError):
f.SetFraction("hello") # type:ignore[arg-type]
f.SetFraction("hello") # type: ignore[arg-type]
with pytest.raises(ValueError):
f.SetFraction((1, 2, 3)) # type:ignore[arg-type]
f.SetFraction((1, 2, 3)) # type: ignore[arg-type]

assert FractionValue(3).GetFraction() == Fraction(0, 1)

Expand All @@ -36,17 +36,17 @@ def testPartsArentNone() -> None:
FractionValue can't be initialized nor modified to have None as number or fraction part.
"""
with pytest.raises(TypeError):
FractionValue(1, None) # type:ignore[arg-type]
FractionValue(1, None) # type: ignore[arg-type]
with pytest.raises(TypeError):
FractionValue(None, (0 / 1)) # type:ignore[arg-type]
FractionValue(None, (0 / 1)) # type: ignore[arg-type]
with pytest.raises(TypeError):
FractionValue(None, None) # type:ignore[arg-type]
FractionValue(None, None) # type: ignore[arg-type]

f = FractionValue(1, Fraction(0, 1))
with pytest.raises(TypeError):
f.SetNumber(None) # type:ignore[arg-type]
f.SetNumber(None) # type: ignore[arg-type]
with pytest.raises(TypeError):
f.SetFraction(None) # type:ignore[arg-type]
f.SetFraction(None) # type: ignore[arg-type]


def testMatchFractionPart() -> None:
Expand Down
14 changes: 7 additions & 7 deletions src/barril/curve/_tests/test_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def testCurves(unit_database) -> None:
domain10 = Array("time", values=numpy.array(list(range(10)), dtype=numpy.int32), unit="s")

with pytest.raises(ValueError):
Curve(values10, domain9) # type:ignore[arg-type]
Curve(values10, domain9) # type: ignore[arg-type]

c = Curve(values10, domain10) # type:ignore[arg-type]
c = Curve(values10, domain10) # type: ignore[arg-type]

with pytest.raises(ValueError):
c.SetDomain(domain9) # type:ignore[arg-type]
c.SetDomain(domain9) # type: ignore[arg-type]
with pytest.raises(ValueError):
c.SetImage(values9) # type:ignore[arg-type]
c.SetImage(values9) # type: ignore[arg-type]


def testSlice(unit_database) -> None:
Expand All @@ -73,13 +73,13 @@ def MakeArray(values):
def testCurveRepr(unit_database) -> None:
q1 = ObtainQuantity("m", "length")
q2 = ObtainQuantity("d", "time")
curve = Curve(Array(q1, []), Array(q2, [])) # type:ignore[arg-type]
curve = Curve(Array(q1, []), Array(q2, [])) # type: ignore[arg-type]
assert "Curve(m, d)[]" == repr(curve)

curve = Curve(Array(q1, list(range(3))), Array(q2, list(range(3)))) # type:ignore[arg-type]
curve = Curve(Array(q1, list(range(3))), Array(q2, list(range(3)))) # type: ignore[arg-type]
assert "Curve(m, d)[(0, 0) (1, 1) (2, 2)]" == repr(curve)

curve = Curve(Array(q1, list(range(100))), Array(q2, list(range(100)))) # type:ignore[arg-type]
curve = Curve(Array(q1, list(range(100))), Array(q2, list(range(100)))) # type: ignore[arg-type]
expected = (
"Curve(m, d)[(0, 0) (1, 1) (2, 2) (3, 3) (4, 4) (5, 5) "
"(6, 6) (7, 7) (8, 8) (9, 9) (10, 10) (11, 11) "
Expand Down
8 changes: 4 additions & 4 deletions src/barril/curve/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@ def __getitem__(self, index: int) -> tuple[float, float]: ...
def __getitem__(self, index: slice) -> tuple[ValuesType, ValuesType]: ...

def __getitem__(self, index: Union[int, slice]) -> tuple[Any, Any]:
d = self.GetDomain().GetValues()[index] # type:ignore[index]
i = self.GetImage().GetValues()[index] # type:ignore[index]
d = self.GetDomain().GetValues()[index] # type: ignore[index]
i = self.GetImage().GetValues()[index] # type: ignore[index]
return d, i

def __repr__(self) -> str:
image = self.GetImage()
domain = self.GetDomain()

xy = []
for i, (x, y) in enumerate(zip(image, domain)): # type:ignore[call-overload]
for i, (x, y) in enumerate(zip(image, domain)): # type: ignore[call-overload]
if i > 20:
xy.append(" ... ")
break
xy.append(f"({x}, {y})")

return "Curve({}, {})[{}]".format(
image.unit, domain.unit, " ".join(xy) # type:ignore[attr-defined]
image.unit, domain.unit, " ".join(xy) # type: ignore[attr-defined]
)
4 changes: 2 additions & 2 deletions src/barril/curve/curve_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class ICurve(Interface, TypeCheckingSupport):
The curve is an element that has values and domain for those values.
"""

def GetImage(self) -> Array: # type:ignore[empty-body]
def GetImage(self) -> Array: # type: ignore[empty-body]
"""
:returns:
An IArray -- which is an IObjectWithQuantity with the image for this curve
"""

def GetDomain(self) -> Array: # type:ignore[empty-body]
def GetDomain(self) -> Array: # type: ignore[empty-body]
"""
:returns:
An {IArray} -- which is an IObjectWithQuantity with the domain for this curve
Expand Down
10 changes: 5 additions & 5 deletions src/barril/units/_abstractvaluewithquantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
# Support for creating a scalar as:
# Scalar(10, 'm')
# Scalar(10, 'm', 'length')
value, unit, category = category, value, unit # type:ignore[assignment]
value, unit, category = category, value, unit # type: ignore[assignment]

if value is None or unit is None:
if value is None:
Expand All @@ -75,7 +75,7 @@ def __init__(
unit is not None
), "If category and value are given, the unit must be specified too."

quantity = ObtainQuantity(unit, category) # type:ignore[arg-type, assignment]
quantity = ObtainQuantity(unit, category) # type: ignore[arg-type, assignment]

self._quantity = quantity
self._InternalCreateWithQuantity(quantity, value, unit_database)
Expand Down Expand Up @@ -192,9 +192,9 @@ def CreateWithQuantity(cls: type[T], quantity: Quantity, *args: object, **kwargs
class Stub:
pass

stub = Stub() # type:ignore[assignment]
stub.__class__ = cls # type:ignore[assignment]
stub._InternalCreateWithQuantity(quantity, *args, **kwargs) # type:ignore[attr-defined]
stub = Stub() # type: ignore[assignment]
stub.__class__ = cls # type: ignore[assignment]
stub._InternalCreateWithQuantity(quantity, *args, **kwargs) # type: ignore[attr-defined]
return cast(T, stub)

# Copy -----------------------------------------------------------------------------------------
Expand Down
18 changes: 9 additions & 9 deletions src/barril/units/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def __init__(self, category: str, values: ValuesType, unit: str): ...
@overload
def __init__(self, category: Quantity, values: ValuesType): ...

def __init__( # type:ignore[misc]
def __init__( # type: ignore[misc]
self, category: str, values: Any = None, unit: Any = None
) -> None:
super().__init__(category, value=values, unit=unit)

def _InternalCreateWithQuantity( # type:ignore[override]
def _InternalCreateWithQuantity( # type: ignore[override]
self,
quantity: Quantity,
values: Optional[ValuesType] = None,
Expand All @@ -113,7 +113,7 @@ def CheckValidity(self) -> None:
"""
self.ValidateValues(self._value, self._quantity)

def CreateCopy( # type:ignore[override]
def CreateCopy( # type: ignore[override]
self: SelfT,
values: Optional[ValuesType] = None,
unit: Optional[str] = None,
Expand Down Expand Up @@ -146,7 +146,7 @@ def IsListOfTuples(v: Any) -> bool:
Convert = self._quantity.Convert
for elem in values:
result.append(tuple(Convert(v, unit) for v in elem))
return type(values)(result) # type:ignore[call-arg, arg-type]
return type(values)(result) # type: ignore[call-arg, arg-type]

else:
return self._quantity.Convert(values, unit)
Expand Down Expand Up @@ -276,10 +276,10 @@ def FromScalars(
return cls.CreateEmptyArray()
elif category is None:
category = UnitDatabase.GetSingleton().GetDefaultCategory(unit)
return cls(values=[], unit=unit, category=category) # type:ignore[arg-type]
return cls(values=[], unit=unit, category=category) # type: ignore[arg-type]
else:
assert unit is None
return cls( # type:ignore[call-overload]
return cls( # type: ignore[call-overload]
values=[], unit=unit, category=category
) # This actually will raise an exception

Expand Down Expand Up @@ -416,7 +416,7 @@ def _DoOperation(self, p1: SelfT, p2: SelfT, operation: str) -> SelfT:
if values_iteration.IsNumpy():
v0, v1 = next(iter(values_iteration))
q, v = operation_func(q1, q2, v0, v1)
return self.__class__.CreateWithQuantity(q, v) # type:ignore[return-value]
return self.__class__.CreateWithQuantity(q, v) # type: ignore[return-value]
else:
# not numpy: create a new structure to hold the values
result = []
Expand All @@ -431,5 +431,5 @@ def _DoOperation(self, p1: SelfT, p2: SelfT, operation: str) -> SelfT:
)

if values_iteration.IsTuple():
result = tuple(result) # type:ignore[assignment]
return self.__class__.CreateWithQuantity(q, result) # type:ignore[return-value]
result = tuple(result) # type: ignore[assignment]
return self.__class__.CreateWithQuantity(q, result) # type: ignore[return-value]
10 changes: 5 additions & 5 deletions src/barril/units/_fixedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, dimension: int, category: str, unit: str): ...
@overload
def __init__(self, dimension: int, category: "Quantity", values: ValuesType): ...

def __init__( # type:ignore[misc]
def __init__( # type: ignore[misc]
self, dimension: int, category: str, values: Any = None, unit: Any = None
) -> None:
"""
Expand All @@ -80,7 +80,7 @@ def __init__( # type:ignore[misc]

Array.__init__(self, category, values, unit)

def _InternalCreateWithQuantity( # type:ignore[override]
def _InternalCreateWithQuantity( # type: ignore[override]
self,
quantity: "Quantity",
values: Optional[ValuesType] = None,
Expand Down Expand Up @@ -120,7 +120,7 @@ def _InternalCreateWithQuantity( # type:ignore[override]

Array._InternalCreateWithQuantity(self, quantity, values)

def CreateCopy( # type:ignore[override]
def CreateCopy( # type: ignore[override]
self,
values: Optional[ValuesType] = None,
unit: Optional[str] = None,
Expand All @@ -147,7 +147,7 @@ def CheckValues(self, values: ValuesType, dimension: Optional[int] = None) -> No
raise ValueError(msg % (dimension, len(values)))

@classmethod
def CreateEmptyArray( # type:ignore[override]
def CreateEmptyArray( # type: ignore[override]
cls, dimension: int, values: Optional[ValuesType] = None
) -> "FixedArray":
"""
Expand Down Expand Up @@ -243,6 +243,6 @@ def IndexAsScalar(self, index: int, quantity: Optional["Quantity"] = None) -> "S

if quantity is None:
quantity = self.GetQuantity()
return Scalar( # type:ignore[call-overload]
return Scalar( # type: ignore[call-overload]
quantity, self.GetValues(unit=quantity.GetUnit())[index]
)
2 changes: 1 addition & 1 deletion src/barril/units/_fraction_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def CheckValidity(self) -> None:
# Value ----------------------------------------------------------------------------------------
def GetAbstractValue(
self, unit: Optional[str] = None
) -> FractionValue: # type:ignore[override]
) -> FractionValue: # type: ignore[override]
"""
:param unit:
"""
Expand Down
16 changes: 8 additions & 8 deletions src/barril/units/_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def ObtainQuantity(

if isinstance(unit, dict):
assert category is None
if len(unit) == 1 and next(iter(unit.values()))[1] == 1: # type:ignore[comparison-overlap]
if len(unit) == 1 and next(iter(unit.values()))[1] == 1: # type: ignore[comparison-overlap]
# Although passed as composing, it's a simple case
category, (unit, _exp) = next(iter(unit.items())) # type:ignore[assignment]
category, (unit, _exp) = next(iter(unit.items())) # type: ignore[assignment]
else:
key: list[Any] = [
(category, tuple(unit_and_exp)) for (category, unit_and_exp) in unit.items()
Expand All @@ -110,7 +110,7 @@ def ObtainQuantity(
quantity = quantities_cache[tuple(key)] = Quantity(unit, None, unknown_unit_caption)
return quantity

key = (category, unit, unknown_unit_caption) # type:ignore[assignment]
key = (category, unit, unknown_unit_caption) # type: ignore[assignment]
try:
return quantities_cache[key]
except KeyError:
Expand Down Expand Up @@ -379,7 +379,7 @@ def __init__(
(unit, exp) for _category, (unit, exp) in self._category_to_unit_and_exps.items()
)
self._composing_categories = tuple(self._category_to_unit_and_exps.keys())
self._category_info = None # type:ignore[assignment]
self._category_info = None # type: ignore[assignment]
return

self._is_derived = False
Expand Down Expand Up @@ -413,7 +413,7 @@ def __init__(
# an operation.
category_to_unit_and_exps = OrderedDict()
category_to_unit_and_exps[category] = [unit, 1]
self._category_to_unit_and_exps = category_to_unit_and_exps # type:ignore[assignment]
self._category_to_unit_and_exps = category_to_unit_and_exps # type: ignore[assignment]

self._category = category
self._quantity_type = unit_database.GetCategoryQuantityType(category)
Expand Down Expand Up @@ -749,7 +749,7 @@ def CheckValue(self, value: Any, use_literals: bool = False) -> None:
# convert value to check limit
if unit != category_info.default_unit:
value = self.ConvertScalarValue(
value, category_info.default_unit # type:ignore[arg-type]
value, category_info.default_unit # type: ignore[arg-type]
)

if category_info.min_value is not None:
Expand Down Expand Up @@ -779,7 +779,7 @@ def GetComposingCategories(self) -> Union[tuple[str, ...], str]:
return self._composing_categories

def GetComposingUnits(self) -> Union[tuple[UnitExponentTuple, ...], str]:
return self._composing_units # type:ignore[return-value]
return self._composing_units # type: ignore[return-value]

def GetComposingUnitsJoiningExponents(self) -> tuple[UnitExponentTuple, ...]:
self._composing_units_joining_exponents: tuple[UnitExponentTuple, ...]
Expand Down Expand Up @@ -818,7 +818,7 @@ def __hash__(self) -> int:
(category, tuple(unit_and_exp))
for (category, unit_and_exp) in self._category_to_unit_and_exps.items()
)
lst.append(self._unknown_unit_caption) # type:ignore[arg-type]
lst.append(self._unknown_unit_caption) # type: ignore[arg-type]
self._hash = hash(tuple(lst))
return self._hash

Expand Down
4 changes: 2 additions & 2 deletions src/barril/units/_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, value: float, unit: str, category: Optional[str] = None): ...
@overload
def __init__(self, value_and_unit: tuple[float, str]): ...

def __init__( # type:ignore[misc]
def __init__( # type: ignore[misc]
self, category: Any, value: Any = None, unit: Any = None
) -> None:
if category.__class__ is tuple:
Expand Down Expand Up @@ -284,7 +284,7 @@ def AlmostEqual(self, other: "Scalar", precision: int) -> bool:
and self._quantity == other._quantity
)

def __hash__(self) -> int: # type:ignore[override]
def __hash__(self) -> int: # type: ignore[override]
return hash((self._value, self._quantity))

def __lt__(self, other: Any) -> bool:
Expand Down
Loading
Loading