-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Description
(Apologies if this has already been answered somewhere else, I've looked but couldn't find a duplicate, it's kind of the opposite of #520)
I'm trying to get pydantic to work better with mypy. This is taken from pydantic/pydantic#245.
class Model(BaseModel):
age: int
m = Model(age=5)
print(m.foobar)
This code obviously raises an AttributeError
with python, but mypy doesn't complain since as per #520 the __getattr__
method is defined so mypy can't know if m.foobar
exists.
Is there any way to get mypy to fail in a case like this?
The only thing I can think of is to define BaseModel
differently based on TYPE_CHECKING
so __getattr__
isn't defined in that case. This that the best/only way to go or is there some magic comment or annotation I can add to get mypy to ignore __getattr__
?
schneiderfelipe
Metadata
Metadata
Assignees
Labels
No labels