Skip to content

Commit

Permalink
Fixing some more linting
Browse files Browse the repository at this point in the history
  • Loading branch information
pesap committed May 21, 2024
1 parent 13bc0c1 commit 8bc6270
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/infrasys/base_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BaseQuantity(ureg.Quantity): # type: ignore

__base_unit__ = None

def __init_subclass__(cls, **kwargs) -> None:
def __init_subclass__(cls, **kwargs):
if not cls.__base_unit__:
raise TypeError("__base_unit__ should be defined")
super().__init_subclass__(**kwargs)
Expand All @@ -44,23 +44,23 @@ def __get_pydantic_core_schema__(

# Required for pydantic validation
@classmethod
def validate(cls, value, *_):
def validate(cls, value, *_) -> "BaseQuantity":
if isinstance(value, BaseQuantity):
if cls.__base_unit__:
assert value.check(
cls.__base_unit__
), f"Unit must be compatible with {cls.__base_unit__}"
return value
return cls(value)
if isinstance(value, pint.Quantity):
if cls.__base_unit__:
assert value.check(
cls.__base_unit__
), f"Unit must be compatible with {cls.__base_unit__}"
return value
return cls(value.magnitude, value.units)
else:
raise ValueError(f"Invalid type for BaseQuantity: {type(value)}")
if isinstance(value, cls):
return value
return cls(value)
return value

@staticmethod
Expand Down
1 change: 0 additions & 1 deletion src/infrasys/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,6 @@ def _deserialize_fields(
values[field] = composed_value
elif isinstance(metadata.fields, SerializedQuantityType):
quantity_type = cached_types.get_type(metadata.fields)
# values[field] = quantity_type.from_dict(value)
values[field] = quantity_type(value=value["value"], units=value["units"])
else:
msg = f"Bug: unhandled type: {field=} {value=}"
Expand Down

0 comments on commit 8bc6270

Please sign in to comment.