Minimal example:
from pint import UnitRegistry, Quantity, Context
import decimal
ureg = UnitRegistry(non_int_type=decimal.Decimal)
ureg.define("CV = 2.6 L")
print(ureg.Quantity(decimal.Decimal("1.0"), "CV").to("L")) # 2.60 L as expected
# Redefine using context
c = Context('columnvolume')
c.redefine("CV = 3.14 L")
ureg.add_context(c)
ureg.enable_contexts('columnvolume')
print(ureg.Quantity(decimal.Decimal("1.0"), "CV").to("L")) # Raises exception
Analysis:
I believe that this issue is caused by pint.facets.context.objects.Context.redefine which doesn't apply the non_int_type used in the ureg. Changing the line cfg = ParserConfig(float) to cfg = ParserConfig(decimal.Decimal) fixes the exception. Perhaps pint.facets.context.objects.Context.redefine should have a non_int_type parameter?
Minimal example:
Analysis:
I believe that this issue is caused by
pint.facets.context.objects.Context.redefinewhich doesn't apply thenon_int_typeused in theureg. Changing the linecfg = ParserConfig(float)tocfg = ParserConfig(decimal.Decimal)fixes the exception. Perhapspint.facets.context.objects.Context.redefineshould have anon_int_typeparameter?