fix: Correct module naming and registration #23
Merged
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.
Closes #21
As a workaround to pyo3#759,
create_init_submodule!
updatessys.modules
to register a module.sys.modules
is a mapping of the fully qualified path to a module, to the module object itself.create_init_submodule!
was using the fully qualified path as both the key and the name of the module. This made submodule import paths awkward to work with, especially with tooling, and in some cases it even breaks imports.For example, quil-py defines a module
quil
, with submodulesexpression
,instructions
,program
, andvalidation
.Using the current release of
rigetti-pyo3
, notice the repetition ofquil.expression
when inspecting thequil
module. This repetition also breaks theimport quil.expression
syntax, because the real path isquil.quil.expression
but that module is impossible to access with the usual import syntax, sincequil.quil.expression
is recognized as three modules delimited by a.
by Python, but really it's just two modules, "quil" and "quil.expression".After this fix, the
quil
module works as expected and we can importquil.expression
successfully.