Skip to content

Avoid lint error on forward type reference in TVMScript #11192

@yelite

Description

@yelite

In TVMScript, there are places where literal string is used in type annotation as type parameter. For instance,

@T.prim_func
def main(A: T.Buffer[(8,), "float32"], B: T.Buffer[(8,), "float32"]):
    ...

This will result in lint error undefined name 'float32' since linter (or type checker) treats literal string in type annotation as forward references. While there will not be any runtime errors, this makes editing TVMScript in modern editor less pleasant. This issue is opened to discuss the potential workaround for this problem.

One possible approach is to have a magic object to turn symbol into string, like

class TypeString:
    def __getattribute__(self, name):
        return name

T.type = TypeString()

@T.prim_func
def main(A: T.Buffer[(8,), T.type.float32], B: T.Buffer[(8,), T.type.float32]):
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    tir:printerTIR printer:python/tvm/script, src/printer/tir_text_printer.cc, src/printer/tvmscript_printer.cctype: language

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions