Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix GenericPlainRegistry getattr type #2045

Merged
merged 4 commits into from
Aug 19, 2024
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
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)
Loading