Skip to content
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

Incorrect error message #223

Open
mechsin opened this issue Nov 16, 2023 · 2 comments
Open

Incorrect error message #223

mechsin opened this issue Nov 16, 2023 · 2 comments

Comments

@mechsin
Copy link

mechsin commented Nov 16, 2023

I ran across an incorrect error message while using tomli.loads. See the snippet below

import tomli
>>> tomli_str = b'test="a"'
>>> tomli.loads(tomli_str)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "venv\lib\site-packages\tomli\_parser.py", line 74, in loads
    src = __s.replace("\r\n", "\n")
TypeError: a bytes-like object is required, not 'str'

Note the actual text of of the type error. It indicates it wants "a bytes-like object is required, not 'str'". Except it was passed a bytes like object and consulting the documentation loads actually wants a str object. So error message text is wrong and in fact opposite of what the function actually wants.

I generated this error using tomli 2.0.1

@hukkin
Copy link
Owner

hukkin commented Dec 12, 2023

Thanks for the issue!

The error message is bad because it is not raised directly by tomli but the bytes.replace method of the unsupported bytes object. Tomli let's it bubble up.

Question to @encukou: Does tomllib (or CPython in general) care about PRs that improve error messages like this?

@encukou
Copy link
Collaborator

encukou commented Dec 12, 2023

Yes, the CPython PRs would be welcome. Ping me so it doesn't get lost in the review queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants