feverdreme
feverdreme

Reputation: 527

How to resolve undefined type in pyi file?

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?

Upvotes: -1

Views: 615

Answers (1)

JM0
JM0

Reputation: 447

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: ...

Upvotes: -1

Related Questions