Let Context.redefine parse magnitudes with the registry's non_int_type#2328
Open
apoorva-01 wants to merge 1 commit into
Open
Let Context.redefine parse magnitudes with the registry's non_int_type#2328apoorva-01 wants to merge 1 commit into
apoorva-01 wants to merge 1 commit into
Conversation
Context.redefine always parsed the new definition with ParserConfig(float), so redefining a unit for a registry configured with non_int_type=decimal.Decimal produced a float scale. Converting a Decimal quantity through that context then raised TypeError from mixing float and Decimal. Add a non_int_type parameter (default float) so callers can parse the redefinition with the same numerical type as the registry, mirroring the non_int_type already accepted by Context.from_lines.
Merging this PR will not alter performance
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2301
pre-commit run --all-filesContext.redefinealways parsed the definition withParserConfig(float), so redefining a unit on anon_int_type=decimal.Decimalregistry produced a float scale and conversion blew up withTypeError: unsupported operand type(s) for ** or pow(): 'float' and 'decimal.Decimal'.I added a
non_int_typeargument (defaultfloat) so the redefinition can be parsed with the registry's type — option 1 from the discussion, matchingContext.from_lines.One thing to note: it's opt-in, so the caller passes
non_int_type=decimal.Decimal; it doesn't auto-inherit from the registry. If you'd rather it inherit, I can move the parsing intoadd_contextinstead — happy to switch.