-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't workingregression
Description
Describe the bug
When using the @pydantic.dataclasses.dataclass decorator, any reference to a class member (attribute, method, etc) is raised with a reportedAttributeAccessIssue.
Notably, the builtin dataclasses library does not have this issue.
Code or Screenshots
Here is some minimal code that reproduces this failure.
import pydantic
@pydantic.dataclasses.dataclass(frozen=True)
class SubModel:
a: int
b: int
@pydantic.dataclasses.dataclass(frozen=True)
class Model:
foo: SubModel
bar: int
@property
def a_from_foo(self) -> int:
return self.foo.a
if __name__ == '__main__':
m = Model(**{'foo': {'a': 1, 'b': 2}, 'bar': 3})
print('model', m)
print('a_from_foo', m.a_from_foo)The pydantic version used in testing is 2.9.2
The script is functional.
python pydantic_demo.py
model Model(foo=SubModel(a=1, b=2), bar=3)
a_from_foo 1
But pyright 1.1.407 flags this as an error.
pnpm exec pyright --version
pyright 1.1.407
pnpm exec pyright pydantic_demo.py
pydantic_demo.py
pydantic_demo.py:17:25 - error: Cannot access attribute "a" for class "PydanticDataclass"
Attribute "a" is unknown (reportAttributeAccessIssue)
pydantic_demo.py:23:27 - error: Cannot access attribute "a_from_foo" for class "PydanticDataclass"
Attribute "a_from_foo" is unknown (reportAttributeAccessIssue)
2 errors, 0 warnings, 0 informations
pyright 1.1.406 is happy with the file
pnpm exec pyright --version
pyright 1.1.406
pnpm exec pyright pydantic_demo.py
0 errors, 0 warnings, 0 informations
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't workingregression