Error: PythonModuleBuilder . def_method

Greetings,

I’ve just updated to 0.26.2.0.dev2026012905 (from 0.25.7) and now I’m getting this error when trying to use the PythonModuleBuilder.


/Users/ted/dev/MMMAudio/ManyOscillatorsBridge.mojo:219:13: error: invalid call to ‘def_method’: failed to infer parameter ‘method_type’
.def_methodMMMAudioBridge.next

The code is below. VSCode is suggesting an error on the line: .def_method[MMMAudioBridge.next("next")`

The error occurs on whatever line the first .def_method occurs so it seems the error is with that “invalid call” as suggested by the error above. I looked at the changelog but couldn’t see what would have changed to be causing this error.

Thanks for any help or suggestions!

@export
fn PyInit_ManyOscillatorsBridge() -> PythonObject:
    try:
        var m = PythonModuleBuilder("MMMAudioBridge")

        _ = (
            m.add_type[MMMAudioBridge]("MMMAudioBridge")
            .def_py_init[MMMAudioBridge.py_init]()
            .def_method[MMMAudioBridge.next]("next")
            .def_method[MMMAudioBridge.set_screen_dims]("set_screen_dims")
            .def_method[MMMAudioBridge.update_mouse_pos]("update_mouse_pos")
            .def_method[MMMAudioBridge.update_bool_msg]("update_bool_msg")
            .def_method[MMMAudioBridge.update_bools_msg]("update_bools_msg")
            .def_method[MMMAudioBridge.update_float_msg]("update_float_msg")
            .def_method[MMMAudioBridge.update_floats_msg]("update_floats_msg")
            .def_method[MMMAudioBridge.update_int_msg]("update_int_msg")
            .def_method[MMMAudioBridge.update_ints_msg]("update_ints_msg")
            .def_method[MMMAudioBridge.update_trig_msg]("update_trig_msg")
            .def_method[MMMAudioBridge.update_trigs_msg]("update_trigs_msg")
            .def_method[MMMAudioBridge.update_string_msg]("update_string_msg")
            .def_method[MMMAudioBridge.update_strings_msg]("update_strings_msg")
            .def_method[MMMAudioBridge.send_raw_hid]("send_raw_hid")
            .def_method[MMMAudioBridge.set_channel_count]("set_channel_count")
        )

        return m.finalize()
    except e:
        abort(String("error creating Python Mojo module:", e))

We were able to figure this out. The entire PythonModuleBuilder syntax changed.

1 Like