Open peter-goldstein opened 3 weeks ago
I'd expect to get c = Quantity(1000, "dimensionless")
Looks like you're most of the way there, I'd change that to
if isinstance(other, self._REGISTRY.Unit) or (isinstance(other, Unit) and self._REGISTRY==other._REGISTRY):
A PR with a fix is welcomed.
the only other place I see an isinstance check with a Unit is L918 in quantity.py so change that too.
Steps to reproduce:
Expected behavior:
c
is a dimensionless unit representing 1000Actual behavior: AttributeError: 'PlainUnit' object has no attribute '_get_non_multiplicative_units'
The offending line is in pint/facets/plain/quantity.py:999:
other
does not have this method, becauseother
is aUnit
, and not aNonMultiplicativeQuantity
. It looks like the bug is coming from quantity.py:989:This is evaluating to
False
, soother
is remaining a Unit rather than being converted to a Quantity. I suspect this isn't quite the right logic for this conditional. I believe the intention is "is this item a Unit and attached to the same registry I am," but what it is actually checking is, "was this item constructed as an instance of my registry's inner class called Unit."(Unnecessary) detail:
pint.Quantity(1, "L")
invokesSharedRegistryObject.__new__
, which gives the created object a field_REGISTRY
pointing to the application registryunits()
property returns aself._REGISTRY.Unit
, which does not have a_REGISTRY
field but is an instance of an inner class of the application registrypint.Unit("mL") invokes
SharedRegistryObject.new`, so again it has the application registry as a field, but it isn't an instance of that registry's inner Unit class