Problem:
I'm using Pydantic to structure my code, and Pyre (aka pyre-check) to type check. In the following sample, the code works and mypy doesn't complain but Pyre gives error:
Uninitialized attribute [13]: Attribute
firstis declared in classNameto have typestrbut is never initialized.
Code:
from __future__ import annotations
from pydantic import BaseModel
class Name(BaseModel):
first: str
n = Name(first="test")
print(n)
Is Pyre incompatible with Pydantic, or is this user error on my part?
I understand Pyre wants to see the attribute initialized (for example first: str = "Bob") but setting such an equality would indicate to Pydantic that the field is optional (it's not).
Other solutions I've considered and discarded:
- Pyre doesn't complain if I make
Namea dataclass (but then I lose Pydantic features) - Adding Field to each attribute eg
first: str = Field(..., alias="first_name")- this seems hacky and labor intensive (there are many such BaseModel classes in my code)
Thanks for your help!