-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Py new #6402
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
Merged
+137
−112
Merged
Py new #6402
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 238
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 856
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 222
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 794
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 527
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 288
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 5642
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 812
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 119
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 2557
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 881
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1354
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1345
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 201
🌐 Web query:
CPython bytes constructor __bytes__ return type error message TypeError💡 Result:
When you call bytes(x), CPython will call x.bytes() (if present) and that method must return a bytes object. If it returns some other type, CPython raises a TypeError such as:
Fix: make bytes return a bytes object (e.g. return b"..." or return some_str.encode('utf-8')). [3]
Sources:
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 731
🏁 Script executed:
# Check the test file for __bytes__ tests cat extra_tests/snippets/builtin_bytes.pyRepository: RustPython/RustPython
Length of output: 20952
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1364
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
The
downcastusage on line 129 is correct; consider adding a specific error for__bytes__returning non-bytes.Line 129 correctly uses
downcast::<PyBytes>()(which accepts subclasses) rather thandowncast_exact. This matches CPython semantics:bytes()returns the__bytes__result directly if it's any bytes instance, including subclasses.However, when
__bytes__returns a non-bytes type, the current code delegates toPyBytesInner::try_from_borrowed_object, which raises a generic error: "can assign only bytes, buffers, or iterables of ints in range(0, 256)". CPython raises a more specific error: "TypeError: bytes returned non-bytes (type X)". Consider adding explicit validation to match CPython's error message.