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
{{ message }}
Repository navigation
Improve invalid input type handling in tomllib.loads #124835
which is otherwise fine, but the message has bytes and str the wrong way around, which can be very confusing. I propose catching the exception and raising a new TypeError with an improved message.
While at it, I also propose catching any AttributeErrors from this line of code and raising the same new TypeError instead. As a result, a sensible TypeError is raised in nearly all cases where incorrect type is passed in.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
I didn't backport because it can change the exception type (also because slightly less confusing error messages that aren't super critical are little more feature than bug, changes to error messages do sometimes break folks)
Activity
gh-124835: `tomllib.loads`: Raise TypeError not AttributeError. Impro…
StanFromIreland commentedon Apr 17, 2025
Do we want to backport this change? It is partly a bug fix (error message is flipped). Maybe it could be split?
See also: #132655
hauntsaninja commentedon Apr 17, 2025
I didn't backport because it can change the exception type (also because slightly less confusing error messages that aren't super critical are little more feature than bug, changes to error messages do sometimes break folks)