GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — "static type has not been initialized" when type lives in another module · Issue #5210 · RustPython/RustPython

"static type has not been initialized" when type lives in another module #5210

New issue
Copy link
New issue
Copy link
Open
Open
"static type has not been initialized" when type lives in another module#5210
Copy link
Labels
C-bugSomething isn't workingSomething isn't working

Description

@rockstar
rockstar
opened on Apr 4, 2024
Issue body actions

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.)

Activity

  1. rockstar
    added
    C-bugSomething isn't workingSomething isn't working
    on Apr 4, 2024
  2. youknowone commented on Apr 11, 2024

    @youknowone
    youknowone
    on Apr 11, 2024
    Member
    More actions

    static types are initializable in Rust side code. So python code doesn't provide that much information.

    Technically it means StaticType::init_builtin_types is not called for the type. It is usually called by <module_name>::make_module() if you created a module named <module_name> with #[pymodule].

    One of the possible reason can be separated but not initialized python modules. If you created modules named A and B, referencing A::SomeType in B, running code including B but didn't run A::make_module() yet.

  3. youknowone commented on Apr 26, 2024

    @youknowone
    youknowone
    on Apr 26, 2024
    Member
    More actions

    Do you have any advice to make this less confusing?

  4. dchiquito commented on May 2, 2024

    @dchiquito
    dchiquito
    on May 2, 2024
    Contributor
    More actions

    FWIW I ran into this same problem trying to add typing to the stdlib. After several hours of digging I found the essential_init phase of the vm initialization process.

    I think the only real way to improve this discovery process is documentation. Either an example which covers this use case (with useful comments), or some documentation on all the magical [py*] macros.

    Reacted by Jeong, YunWon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.