I want to keep my type aliases in one module, say my_types, to be able to
use them anywhere in my application (similar to the standard typing module).
But mypy complains that the forward reference to class X is not defined.
If I define class X later in that same module, it’s okay, but if it defined
in another one, mypy gets upset.
So my question is, how do I keep all my type aliases in one module without mypy producing an error about forward references that are not defined in the same module? Or is that a wrong approach somehow?
Here is my example code:
from my_types import SomeXs
class X:
pass
Type aliases are defined like so:
# my_types.py
from typing import List
SomeXs = List['X']
When I run mypy, I get an error that X is not defined:
$ mypy module.py
my_types.py:4: error: Name 'X' is not defined
Found 1 error in 1 file (checked 1 source file)