Skip to content

Commit

Permalink
Coerce dimensionless values of SizeConstraint to values with dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
skycastlelily committed Jul 5, 2024
1 parent a42eb01 commit fd57155
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tmt/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ def _from_specification(
as_quantity: bool = True,
as_cast: Optional[Callable[[str], ConstraintValueT]] = None,
original_constraint: Optional['Constraint[Any]'] = None,
allowed_operators: Optional[list[Operator]] = None
allowed_operators: Optional[list[Operator]] = None,
unit: Optional[Any] = "bytes"
) -> T:
"""
Parse raw constraint specification into our internal representation.
Expand Down Expand Up @@ -560,7 +561,7 @@ def _from_specification(
if not isinstance(
value,
pint.Quantity): # type: ignore[reportUnnecessaryIsInstance,unused-ignore]
value = pint.Quantity(value)
value = pint.Quantity(value, unit)

elif as_cast is not None:
value = as_cast(raw_value)
Expand Down Expand Up @@ -672,14 +673,16 @@ def from_specification(
name: str,
raw_value: str,
original_constraint: Optional['Constraint[Any]'] = None,
allowed_operators: Optional[list[Operator]] = None
allowed_operators: Optional[list[Operator]] = None,
unit: Optional[Any] = 'bytes'
) -> T:
return cls._from_specification(
name,
raw_value,
as_quantity=True,
original_constraint=original_constraint,
allowed_operators=allowed_operators
allowed_operators=allowed_operators,
unit=unit
)


Expand Down

0 comments on commit fd57155

Please sign in to comment.