You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
other does not have this method, because other is a Unit, and not a NonMultiplicativeQuantity. It looks like the bug is coming from quantity.py:989:
if isinstance(other, self._REGISTRY.Unit):
other = 1 * other
This is evaluating to False, so other 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") invokes SharedRegistryObject.__new__, which gives the created object a field _REGISTRY pointing to the application registry
The units() property returns a self._REGISTRY.Unit, which does not have a _REGISTRY field but is an instance of an inner class of the application registry
pint.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
The text was updated successfully, but these errors were encountered:
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 classThe text was updated successfully, but these errors were encountered: