mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Feature Request] Add a `type` builtin

Open yuanjv opened this issue 1 year ago • 3 comments

Bug Description

type() is not in mojo

Steps to Reproduce

when print(type) was run, the expected output is "<class 'type'>" but the actual output is "error: Expression: use of unknown declaration 'type'".

Context

yuanjv avatar May 12 '23 16:05 yuanjv

Unfortunately you need to do something like this at this point

let py = Python.import_module("builtins")
py.print(py.type) # <class 'type'>

czheo avatar May 13 '23 19:05 czheo

The issue with adding the type bultin to Mojo is that we don't have a runtime type representation yet. I.e. in Python, type returns a type instance that can be used like a class.

Mogball avatar May 22 '23 16:05 Mogball

As a temporary workaround, maybe it could return a string representation of the type? Being able to debug types more easily would be very handy.

DayDun avatar May 22 '23 16:05 DayDun