Skip to content
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

Type checking fails when records are defined in a world with functions #88

Open
alec-deason opened this issue Apr 22, 2024 · 1 comment

Comments

@alec-deason
Copy link

alec-deason commented Apr 22, 2024

I think this is actually a bug but it may not be one that idiomatic wit files would trigger so it may not be an important issue but I'll post it anyway just in case.

When records are defined in a world along side functions which use the record type, the functions are generated first in the binding's init.py file so that type checking fails due to the undefined type.

For example, this wit file will not produce usable bindings:

package example:broken;

world broken-world {
    record a-record {
        field: s32
    }

    import get-a-record: func() -> a-record;
    export do-stuff: func() -> a-record;
}

My naive fix was to stick from __future__ import annotations at the top of the __init__.py file and that does work. But then I realized that the idiomatic thing to do seems to be to put type definitions in a separate types interface and import from there. Doing that produces valid bindings without having to change componentize_py at all.

@dicej
Copy link
Collaborator

dicej commented Apr 22, 2024

Good catch. Glad you found a workaround, but we should also fix componentize-py so it generates valid bindings for any valid WIT world, and ideally without having to use __future__ if possible. I'll play around with it when I get a chance.

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

No branches or pull requests

2 participants