RustPython / RustPython/RustPython
"static type has not been initialized" when type lives in another module
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 22.4k
- Forks
- 1.5k
- Avg merge
- 16h 33m
- Merged PRs (30d)
- 165
Description
Summary
Let's say we have two separate native modules, things_types which defines a Thing class, and things which has a get_all() -> List[Thing] function. Then I write the following code.
import things
my_things = things.get_all()
for thing in my_things:
thing.do_stuff()
Expected
I would expect this to work just fine, for Thing instances to be returned from things.get_all() and for the pymethod do_stuff to be called on each instance.
Actual
An error occurs when calling things.get_all(), which is static type is not initialized.
Workaround
A workaround here is to import things_types as well, but I don't think that's very ergonomic.
Context
I'm creating a set of native modules to be provided to a rustpython interpreter as a sandbox for users. Asking users to import everything, even if they don't need it, is a little awkward. If there was a way I could, in my pymodule itself, intialize the static type easily, I would be happy to do that; I just couldn't find a way in the docs or examples or my journey through the source code (admittedly, my journey through the source code was to figure out the static type is not initialized meaning.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two-module native setup using things_types, things.get_all(), and Thing.do_stuff(); then trace where the static type is initialized when only things is imported. Done means importing only things allows get_all() to return usable Thing instances without the workaround import.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100