GeezerVison is showing github.com — gh-124835: `tomllib.loads`: Raise TypeError not AttributeError. Improve message by hukkin · Pull Request #124587 · python/cpython
Conversation
hukkin
commented
Sep 26, 2024
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
This PR makes tomllib.loads(b"") throw
TypeError: Expected str object, not 'bool'
instead of
TypeError: a bytes-like object is required, not 'str'
Given an input type that doesn't have the replace attribute, it makes tomllib.loads raise the same new TypeError, instead of an AttributeError. Should this be a separate PR though?
The corresponding Tomli PR is hukkin/tomli#229
The issue report is hukkin/tomli#223
Pinging @encukou as requested here hukkin/tomli#223 (comment)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two stances:
- I'm ok with the change but I would let a regular TypeError be propagated instead (e.g., if someone is using a subclass os str for whatever reason).
- I'm not ok with the change because of the "garbage in, garbage out" principle, though it's not really an in/out here. I think
loads should only expect a string.
For the second point, we could do something like isinstance(s, str) but this would restrict the user to always use a string instance and not a UserString object for instance.
I don't know which one is better. But the fact that the message does not help is IMO an inconvenience so I like that you want to fix it. Now, how to fix it, is still something I'm pondering.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
I suggest opening a CPython issue so that we can possibly discuss it. In addition, I think a NEWS entry should be added so that people know about the fact that an AttributeError won't be raised (but for now I'll just add the skip news label)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yes, this should have a NEWS entry (and therefore, an issue) as it changes user-visible behavior.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
hugovk
changed the title
tomllib.loads: Raise TypeError not AttributeError. Improve message
gh-124835: tomllib.loads: Raise TypeError not AttributeError. Improve message
Oct 1, 2024
|
Thanks! I've opened an issue (#124835) and added a NEWS entry.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
picnixz
picnixz left review comments
encukou
Awaiting requested review from encukou
encukou is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|