diff options
author | Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> | 2024-10-02 02:58:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-02 02:58:08 (GMT) |
commit | 9ce90206b7a4649600218cf0bd4826db79c9a312 (patch) | |
tree | e656b4c100f65e7733439d97bf760fa84f17a657 /Lib/tomllib | |
parent | 120729d862f0ef9979508899f7f63a9f3d9623cb (diff) | |
download | cpython-9ce90206b7a4649600218cf0bd4826db79c9a312.zip cpython-9ce90206b7a4649600218cf0bd4826db79c9a312.tar.gz cpython-9ce90206b7a4649600218cf0bd4826db79c9a312.tar.bz2 |
gh-124835: `tomllib.loads`: Raise TypeError not AttributeError. Improve message (#124587)
Diffstat (limited to 'Lib/tomllib')
-rw-r--r-- | Lib/tomllib/_parser.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/tomllib/_parser.py b/Lib/tomllib/_parser.py index 45ca7a8..5671326 100644 --- a/Lib/tomllib/_parser.py +++ b/Lib/tomllib/_parser.py @@ -71,7 +71,12 @@ def loads(s: str, /, *, parse_float: ParseFloat = float) -> dict[str, Any]: # n # The spec allows converting "\r\n" to "\n", even in string # literals. Let's do so to simplify parsing. - src = s.replace("\r\n", "\n") + try: + src = s.replace("\r\n", "\n") + except (AttributeError, TypeError): + raise TypeError( + f"Expected str object, not '{type(s).__qualname__}'" + ) from None pos = 0 out = Output(NestedDict(), Flags()) header: Key = () |