-
Notifications
You must be signed in to change notification settings - Fork 933
use last segment of module name (path) when adding to parent #5375
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
davidhewitt
merged 19 commits into
PyO3:main
from
altendky:correct_parent_module_key_for_submodule
Nov 18, 2025
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9bb69d6
use last segment of module name (path) when adding to parent
altendky f3a7645
add newsfragment
altendky 4455590
format
altendky 01ca587
preliminary tests
altendky 0d6fdff
fmt
altendky fb5725e
doc comment and more test (that fails right now)
altendky 7c4b890
fmt
altendky c053622
separate
altendky ec74932
tweak test layout
altendky 9c9f002
recombine for PyO3 modules compiled for CPython 3.8 or older may only…
altendky 4cb3eb6
again
altendky b69ef46
fmt
altendky 6713f96
Merge branch 'main' into correct_parent_module_key_for_submodule
altendky e1909d5
catchup
altendky e891923
declarative
altendky cd69d88
fmt
altendky a4c60d3
Update newsfragments/5375.fixed.md
altendky cab3fa2
Refactor add_submodule to simplify name extraction
altendky dc0583b
`match` instead of `.map_or()`
altendky 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed `PyModuleMethods::add_submodul()` to use the last segment of the submodule name as the attribute name on the parent module instead of using the full name. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,8 @@ pub struct PyModule(PyAny); | |
| pyobject_native_type_core!(PyModule, pyobject_native_static_type_object!(ffi::PyModule_Type), #checkfunction=ffi::PyModule_Check); | ||
|
|
||
| impl PyModule { | ||
| /// Creates a new module object with the `__name__` attribute set to `name`. | ||
| /// Creates a new module object with the `__name__` attribute set to `name`. When creating | ||
| /// a submodule pass the full path as the name such as `top_level.name`. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
|
|
@@ -513,7 +514,11 @@ impl<'py> PyModuleMethods<'py> for Bound<'py, PyModule> { | |
| } | ||
|
|
||
| fn add_submodule(&self, module: &Bound<'_, PyModule>) -> PyResult<()> { | ||
| let name = module.name()?; | ||
| let name = module | ||
| .name()? | ||
| .call_method1("rpartition", (".",))? | ||
| .get_item(2)? | ||
| .cast_into::<PyString>()?; | ||
|
||
| self.add(name, module) | ||
| } | ||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.