'Appeasing MyPy trying to use an instance variable
If I have the file mypytest/models.py that looks like this:
from typing import Type
class FakeBaseModel:
pass
class FakeDatabase:
Base: Type[FakeBaseModel]
def __init__(self) -> None:
self.Base = FakeBaseModel
db = FakeDatabase()
class FakeModel(db.Base):
pass
And I run mypy ., I get the following output:
[mypytest {mypytest}]$ mypy .
mypytest/models.py:18: error: Name "db.Base" is not defined
Found 1 error in 1 file (checked 2 source files)
Clearly, though, db.Base is defined. How do I get mypy to recognize it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
