Remove Copy from PyPayload by youknowone · Pull Request #6865 · RustPython/RustPython · GitHub
Skip to content

Remove Copy from PyPayload#6865

Merged
youknowone merged 2 commits intoRustPython:mainfrom
youknowone:pypayload-no-copy
Jan 24, 2026
Merged

Remove Copy from PyPayload#6865
youknowone merged 2 commits intoRustPython:mainfrom
youknowone:pypayload-no-copy

Conversation

@youknowone
Copy link
Copy Markdown
Member

@youknowone youknowone commented Jan 24, 2026

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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 24, 2026

@youknowone youknowone marked this pull request as ready for review January 24, 2026 12:47
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a 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)?;

@youknowone youknowone merged commit e0e2926 into RustPython:main Jan 24, 2026
12 of 13 checks passed
@youknowone youknowone deleted the pypayload-no-copy branch January 24, 2026 13:03
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

Successfully merging this pull request may close these issues.

1 participant