Skip to content

Commit

Permalink
fix GenericPlainRegistry getattr type (#2045)
Browse files Browse the repository at this point in the history
  • Loading branch information
theodotk committed Aug 19, 2024
1 parent 0b0ae61 commit 8f12bb9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Pint Changelog
- Added ℓ as alternative for liter
- Support permille units and `‰` symbol (PR #2033, Issue #1963)
- Switch from appdirs to platformdirs.
- Fixes issues related to GenericPlainRegistry.__getattr__ type (PR #2038, Issues #1946 and #1804)


0.24.1 (2024-06-24)
Expand Down
2 changes: 1 addition & 1 deletion pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def __deepcopy__(self: Self, memo) -> type[Self]:
new._init_dynamic_classes()
return new

def __getattr__(self, item: str) -> QuantityT:
def __getattr__(self, item: str) -> UnitT:
getattr_maybe_raise(self, item)

# self.Unit will call parse_units
Expand Down
8 changes: 8 additions & 0 deletions pint/testsuite/test_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2014,3 +2014,11 @@ def test_offset_autoconvert_gt_zero(self):
assert q2 > 0
with pytest.raises(DimensionalityError):
q1.__gt__(ureg.Quantity(0, ""))

def test_types(self):
quantity = self.Q_(1.0, "m")
assert isinstance(quantity, self.Q_)
assert isinstance(quantity.units, self.ureg.Unit)
assert isinstance(quantity.m, float)

assert isinstance(self.ureg.m, self.ureg.Unit)

0 comments on commit 8f12bb9

Please sign in to comment.