How to resolve undefined type in pyi file?

412 views Asked by At

I'm manually creating a pyi file for one of my classes and one of its function return types relies on an enum I made in another file.

Relevant code snippets: Board.pyi

class Board:
    def access(self, i: int, j: int) -> Color: ...

Where Color is the enum. To resolve the fact that Color is not defined in the pyi file, should I just import it from Color.py / Color.pyi or is there another solution that's detailed by PEP?

1

There are 1 answers

0
JM0 On

You can use a normal import statement to bring in any types you need in your .pyi file. The official type stub documentation has this as an example:

from typing_extensions import Literal

def foo(x: Literal[""]) -> int: ...