Improve invalid input type handling in tomllib.loads
#124835
Labels
type-feature
A feature request or enhancement
tomllib.loads
#124835
Feature or enhancement
Proposal:
tomllib.loads
only accepts str as input. Given bytes, it throwsThis is a bubbled up exception from the
replace
method on linecpython/Lib/tomllib/_parser.py
Line 74 in 4129a74
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
Links to previous discussion of this feature:
Original issue report by @mechsin on Tomli's issue tracker: hukkin/tomli#223
PR: #124587
Linked PRs
tomllib.loads
: Raise TypeError not AttributeError. Improve message #124587The text was updated successfully, but these errors were encountered: