componentize-py icon indicating copy to clipboard operation
componentize-py copied to clipboard

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

Open alec-deason opened this issue 2 months ago • 1 comments

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.

alec-deason avatar Apr 22 '24 17:04 alec-deason