fix: Swallow redefinition warnings#72
Conversation
|
@znicholls I don't know how many million lines we have generated because of this. Any other suggestions about how we could handle this? |
znicholls
left a comment
There was a problem hiding this comment.
My small preference would be to add an initialisation argument to add_standards so we can control whether the warning is emitted or not (or perhaps better, just do the _on_redefinition trick around where add_standards is called rather than in add_standards).
Other solutions would require rewriting pint I suspect, so not really in scope (and pint's _on_redefinition attribute is probably good enough).
|
@znicholls I added an argument to |
|
|
||
| This overrides the default units registry behaviour for the duration of | ||
| this method. The previous behaviour is restored afterwards. | ||
| "raise" is not supported here as the redefinitions are required. |
There was a problem hiding this comment.
@lewisjared I'm not sure this is correct. I wonder if it's possible to initialise a pint registry without inheriting the standard definitions, which would then mean that no redefinition is needed (maybe that's the mistake in openscm-units' construction, it inherits from the standard unit registry and therefore always leads to this redefinition).
There was a problem hiding this comment.
I don't think I understand what isn't correct? The docstring is referring to the behaviour of the on_redefinition attribute of the unit registry.
There was a problem hiding this comment.
"the redefinitions are required" is the bit that I'm not sure is correct. The way we have implemented things, the redefinitions are required, but I'm not sure that's true in the absolute sense (i.e. a different way of implementing may have meant this redefinition wasn't required).
There was a problem hiding this comment.
Ahh I see. We should move that to an issue as that is a breaking change and was a much larger undertaking than make the logs go away 😁
|
Thanks. Good one for the back burner
…On Thu, 18 Dec 2025 at 11:48, Jared Lewis ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/openscm_units/_unit_registry.py
<#72 (comment)>:
> """
Add standard units.
Has to be done separately because of pint's weird initialising.
+
+ Parameters
+ ----------
+ on_redefinition:
+ Action to take on redefinition of existing units
+
+ Some existing units (e.g. kt: kilotonne instead of knot) are redefined here.
+ The default behaviour is to ignore redefinition warnings.
+
+ This overrides the default units registry behaviour for the duration of
+ this method. The previous behaviour is restored afterwards.
+ "raise" is not supported here as the redefinitions are required.
#74 <#74>
—
Reply to this email directly, view it on GitHub
<#72 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A3KEXH2L6LABKST4P5CCPAT4CH2XRAVCNFSM6AAAAACPFABEMSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTKOJQGIZTOOBTGA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Description
Swallows the redefinition warnings which are emitted on each import if logging is enabled.
Checklist
Please confirm that this pull request has done the following:
changelog/