ModularM
Modular3y ago
4 replies
Zain Raza (he/him)

Are Type Hints Still Possible in Mojo?

Hi all - I was wondering, is there a way to write a def function in Mojo that uses type hints like in Python 3?

For example I tried writing this earlier. I'm guessing it's not the right approach though, as the compiler gives a warning that cannot use a dynamic value in type specification

from python import Python

def outer_func():
    try:
        let PythonInt = Python.import_module("typing").Int

        def inner_func(x: Int):  # this gives the error
            ...
    except:
        pass


Although in this case, I suppose it'd be a better idea to use the built-in Int type, to let others know what kind of value x is expecting?
Was this page helpful?