You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add the same attributes to tomllib.TOMLDecodeError that json.JSONDecodeError also has, namely: msg, doc, pos, lineno, colno. This will help user facing apps show customized errors to users.
Thoughts on my concern in Discourse about the change breaking TOMLDecodeError init with no arguments would be much appreciated:
Unfortunately, this changes signature of TOMLDecodeError so breaks any users instantiating the error. Not sure why anyone would do that though? Some less breaking options are using keyword arguments, or dynamically injecting attributes after instantiation.
Unfortunately, this changes signature of TOMLDecodeError so breaks any users instantiating the error. Not sure why anyone would do that though? Some less breaking options are using keyword arguments, or dynamically injecting attributes after instantiation.
You can instantiate those errors if you create a custom tomllib extension (e.g., to handle extended syntax not supported by TOML but you still want to use the same exceptions for that).
Thanks all for the feedback! I've updated my PoC draft PR in Tomli to be fully backwards compatible. It also adds a deprecation warning for use of positional arguments, which is simple to remove if folks think it's unnecessary. With it I think we could eventually move to the same exact signature that json.JSONDecodeError has.
Activity
hukkin commentedon Oct 30, 2024
Pinging codeowners @hauntsaninja and @encukou
Thoughts on my concern in Discourse about the change breaking TOMLDecodeError init with no arguments would be much appreciated:
nineteendo commentedon Oct 30, 2024
I would use keywords arguments defaulting to None. Also see PEP-387.
picnixz commentedon Oct 30, 2024
You can instantiate those errors if you create a custom
tomllibextension (e.g., to handle extended syntax not supported by TOML but you still want to use the same exceptions for that).Agreed.
hukkin commentedon Oct 30, 2024
Thanks all for the feedback! I've updated my PoC draft PR in Tomli to be fully backwards compatible. It also adds a deprecation warning for use of positional arguments, which is simple to remove if folks think it's unnecessary. With it I think we could eventually move to the same exact signature that
json.JSONDecodeErrorhas.gh-126175: Add attributes to TOMLDecodeError. Deprecate free-form `__…
pythongh-126175: Add attributes to TOMLDecodeError. Deprecate free-fo…
pythongh-126175: Add attributes to TOMLDecodeError. Deprecate free-fo…