Skip to content

Let Context.redefine parse magnitudes with the registry's non_int_type#2328

Open
apoorva-01 wants to merge 1 commit into
hgrecco:masterfrom
apoorva-01:fix/2301-context-redefine-non-int-type
Open

Let Context.redefine parse magnitudes with the registry's non_int_type#2328
apoorva-01 wants to merge 1 commit into
hgrecco:masterfrom
apoorva-01:fix/2301-context-redefine-non-int-type

Conversation

@apoorva-01

@apoorva-01 apoorva-01 commented Jul 1, 2026

Copy link
Copy Markdown

Closes #2301

  • Executed pre-commit run --all-files
  • Covered by unit tests
  • Documented in docs/
  • Added a CHANGES entry

Context.redefine always parsed the definition with ParserConfig(float), so redefining a unit on a non_int_type=decimal.Decimal registry produced a float scale and conversion blew up with TypeError: unsupported operand type(s) for ** or pow(): 'float' and 'decimal.Decimal'.

I added a non_int_type argument (default float) so the redefinition can be parsed with the registry's type — option 1 from the discussion, matching Context.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 into add_context instead — happy to switch.

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.
@codspeed-hq

codspeed-hq Bot commented Jul 1, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 448 untouched benchmarks
⏩ 448 skipped benchmarks1


Comparing apoorva-01:fix/2301-context-redefine-non-int-type (4a45497) with master (7a927b4)

Open in CodSpeed

Footnotes

  1. 448 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pint.Context does not inherit ureg non_int_type and causes exceptions when ureg has non_int_type=decimal.Decimal

1 participant