diff --git a/CHANGES b/CHANGES index 4b4884d54..9d7de4298 100644 --- a/CHANGES +++ b/CHANGES @@ -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) diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py index c8ce3f2f0..be70a2ca8 100644 --- a/pint/facets/plain/registry.py +++ b/pint/facets/plain/registry.py @@ -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 diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py index 8c6f15c49..26a5ee05d 100644 --- a/pint/testsuite/test_quantity.py +++ b/pint/testsuite/test_quantity.py @@ -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)