PyPayload::into_ref by youknowone · Pull Request #3744 · RustPython/RustPython
Walkthrough
The changes refactor object construction patterns throughout the codebase, replacing direct new_ref methods with standardized approaches using From trait conversions and into_ref methods. New context methods for constructing bytearrays are introduced, and dictionary, list, bytes, and string creation is unified under the context. Several obsolete constructors are removed, and method visibility is updated where needed.
Changes
| File(s) | Change Summary |
|---|---|
vm/src/vm/context.rs |
Standardized object creation: replaced direct new_ref calls with From + into_ref; added new_bytearray. |
vm/src/builtins/list.rsvm/src/builtins/bytearray.rs |
Removed new_ref methods; updated list and bytearray construction to use From + into_ref and context. |
vm/src/builtins/function.rs |
Changed PyBoundMethod construction to use new + into_ref; made new public; removed new_ref. |
vm/src/builtins/classmethod.rs |
Changed bound method construction to use new + into_ref instead of new_ref. |
vm/src/builtins/complex.rs |
Updated ToPyObject for Complex64 to use From + to_pyobject instead of new_ref. |
vm/src/builtins/dict.rs |
Annotated class method with #[inline]. |
vm/src/bytes_inner.rs |
Replaced PyBytes::class(&vm.ctx) with vm.ctx.types.bytes_type in type checks. |
vm/src/class.rs |
Annotated trait methods with #[inline]; made panic path in static_type explicit with a cold function. |
vm/src/warn.rs |
Replaced PyDict::new_ref(ctx) with ctx.new_dict(); cleaned imports. |
examples/call_between_rust_and_python.rs |
Simplified imports; changed list creation to use context's new_list method. |
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant Context
participant PyList
participant PyByteArray
participant PyDict
Caller->>Context: new_list(elements)
Context->>PyList: PyList::from(elements)
PyList-->>Context: PyList instance
Context->>Caller: PyListRef
Caller->>Context: new_bytearray(data)
Context->>PyByteArray: PyByteArray::from(data)
PyByteArray-->>Context: PyByteArray instance
Context->>Caller: PyRef<PyByteArray>
Caller->>Context: new_dict()
Context->>PyDict: PyDict::default()
PyDict-->>Context: PyDict instance
Context->>Caller: PyDictRef
Poem
In fields of code where lists once grew,
The rabbits hopped with something new!
No morenew_ref, justFromand cheer,
With context’s help, all types appear.
Bytearrays, dicts, and lists unite,
Refactored fields now work just right.
🐇✨
Warning
There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
🔧 Clippy (1.86.0)
Updating git repository `https://github.com/youknowone/ferrilab`
error: failed to load source for dependency radium
Caused by:
Unable to update https://github.com/youknowone/ferrilab?branch=fix-nightly#4a301c3a
Caused by:
failed to create directory /usr/local/git/db/ferrilab-ed7d38936952b47e
Caused by:
Permission denied (os error 13)
📜 Recent review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
examples/call_between_rust_and_python.rs(2 hunks)vm/src/builtins/bytearray.rs(6 hunks)vm/src/builtins/classmethod.rs(1 hunks)vm/src/builtins/complex.rs(1 hunks)vm/src/builtins/dict.rs(1 hunks)vm/src/builtins/function.rs(2 hunks)vm/src/builtins/list.rs(4 hunks)vm/src/bytes_inner.rs(2 hunks)vm/src/class.rs(1 hunks)vm/src/vm/context.rs(4 hunks)vm/src/warn.rs(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (11)
- vm/src/warn.rs
- vm/src/builtins/complex.rs
- vm/src/bytes_inner.rs
- examples/call_between_rust_and_python.rs
- vm/src/builtins/dict.rs
- vm/src/builtins/classmethod.rs
- vm/src/builtins/function.rs
- vm/src/class.rs
- vm/src/builtins/bytearray.rs
- vm/src/vm/context.rs
- vm/src/builtins/list.rs
⏰ Context from checks skipped due to timeout of 90000ms (11)
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run tests under miri
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Check Rust code with rustfmt and clippy
✨ Finishing Touches
- 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.