-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom formatters not working with modifiers (Undocumented breaking change in 0.24) #2017
Comments
I think this is the same problem that is fixed in #2011 |
I tried to apply that patch locally, and it does not work. For more debuggin I added a print statement like this https://github.com/hgrecco/pint/pull/2011/files#diff-78134f4ee1d9944843acb020969e96a7d9541da73502c992a4fa1a1567251154L105: def get_formatter(self, spec: str):
if spec == "":
return self._formatters["D"]
for k, v in self._formatters.items():
if k in spec:
return v
+ print(spec)
try:
orphan_fmt = REGISTERED_FORMATTERS[spec]
except KeyError:
return self._formatters["D"] which gives a spec of |
The problem is that is returning an orphan formatter (i.e. one not attached to the registry) Try replacing: try:
orphan_fmt = REGISTERED_FORMATTERS[spec]
except KeyError:
return self._formatters["D"] by for k, v in REGISTERED_FORMATTERS.items():
if k in spec:
orphan_fmt = REGISTERED_FORMATTERS[spec]
break
else:
return self._formatters["D"] Please notice that the check is: If it works, please submit a PR linking to @2011 ping: @andrewgsavage |
should be working now |
Combining a custom format registered with
@pint.register_unit_format
and a modifier does not work on 0.24 any more. Apparently the formatter is silently not even called.Output on pint 0.23
Output on pint 0.24
unfortunately we currently have to still support python 3.9, so only supporting pint 0.24+ is not an option for us, our code has to work on both versions... :-(
The text was updated successfully, but these errors were encountered: