GeezerVison is showing github.com — Remove Copy from PyPayload by youknowone · Pull Request #6865 · RustPython/RustPython
Conversation
youknowone
commented
Jan 24, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
PyPayloads are expected to be exposed via PyRef. Copy/Clone for them doesn't make sense for most of cases. If they are used, that must be careful to take risk to confuse it to PyRef clone
Summary by CodeRabbit
-
New Features
- Added new public methods for module creation and execution on PyModuleDef.
-
Chores
- Removed workspace linting setting for copy implementations.
- Refactored internal trait implementations across various type definitions to improve memory efficiency and ownership semantics.
✏️ Tip: You can customize this high-level summary in your review settings.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Jan 24, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
📝 Walkthrough
Walkthrough
This PR removes Clone and Copy derives from numerous structs and enums across the VM codebase, alongside removing a workspace lint setting, to reduce automatic copy semantics on public types while adding new module creation methods to PyModuleDef.
Changes
| Cohort / File(s) |
Summary |
Configuration and workspace Cargo.toml |
Removed missing_copy_implementations = "warn" workspace lint |
Builtin singleton and primitive types crates/vm/src/builtins/singletons.rs, crates/vm/src/builtins/slice.rs, crates/vm/src/builtins/object.rs |
Removed Clone, Copy derives from PyNone, PyNotImplemented, PyEllipsis, PyBaseObject |
Module definition and related types crates/vm/src/builtins/module.rs |
Removed Clone, Copy from PyModuleDef, PyModuleSlots, PyModule; added public methods create_module() and exec_module() to PyModuleDef for phase-based initialization |
Namespace and descriptor types crates/vm/src/builtins/namespace.rs, crates/vm/src/builtins/descriptor.rs |
Changed PyNamespace from unit-like to empty struct and removed Clone, Copy; removed Clone, Copy from MemberGetter, MemberSetter; removed Clone, Copy from MemberKind |
Protocol and method types crates/vm/src/protocol/mapping.rs, crates/vm/src/protocol/sequence.rs, crates/vm/src/protocol/buffer.rs, crates/vm/src/function/method.rs |
Removed Clone, Copy from PyMappingMethods, PySequenceMethods, BufferMethods; removed Copy from PyMethodDef and HeapMethodDef |
Numeric argument conversion types crates/vm/src/function/number.rs |
Removed Clone, Copy from ArgIntoComplex, ArgIntoFloat, ArgIntoBool |
String and collection argument types crates/vm/src/anystr.rs, crates/vm/src/builtins/zip.rs, crates/vm/src/dict_inner.rs |
Removed Clone, Copy from SplitLinesArgs, ExpandTabsArgs, PyZipNewArgs; removed Clone, Copy from DictSize |
Utility and sequence types crates/vm/src/sliceable.rs, crates/vm/src/stdlib/marshal.rs, crates/vm/src/stdlib/os.rs, crates/vm/src/stdlib/typevar.rs, crates/vm/src/stdlib/typing.rs |
Removed Clone, Copy from SequenceIndex, SaturatedSliceIter, DumpError, TargetIsDirectory, Generic, NoDefault |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
- Implement copyslot #6505: Implements copyslot for protocol methods (PyMappingMethods, PySequenceMethods) whose Copy/Clone traits are modified in this PR
- Apply some clippy lints #6045: Modifies PyNamespace initialization logic in the same file where PyNamespace struct declaration is updated in this PR
- derive
Copy where possible #6844: Inverse operation that adds Copy derives to many of the same types being modified here, creating potential conflicts
Suggested reviewers
Poem
🐰 Copy no more, we declare with glee,
Traits refined, now lean and free!
Clone removed from every place,
Ownership reclaims its grace.
Modules craft themselves with care—
A tidy codebase, fresh and fair! ✨
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title 'Remove Copy from PyPayload' accurately summarizes the main change in the PR, which is reverting Copy/Clone implementations from PyPayload and all dependent public structs and enums throughout the codebase. |
| Docstring Coverage |
✅ Passed |
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
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.
❤️ Share
Comment @coderabbitai help to get the list of available commands and usage tips.
|
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.
Actionable comments posted: 0
Caution Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/vm/src/builtins/module.rs (1)
44-71: Guard against custom create slots returning incomplete modules.
create_module always calls __init_dict_from_def, which unwraps module.def and module.name. If a custom create slot returns a module without those fields initialized, this will panic. Add an explicit guard (or normalize the module) before continuing.
🛡️ Suggested guard
@@
- // Initialize module dict and methods
- PyModule::__init_dict_from_def(vm, &module);
+ // Initialize module dict and methods
+ if module.def.is_none() || module.name.is_none() {
+ return Err(vm.new_system_error(format!(
+ "module '{}' was created without a complete PyModuleDef",
+ self.name.as_str()
+ )));
+ }
+ PyModule::__init_dict_from_def(vm, &module);
module.__init_methods(vm)?;
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.
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.
|