- Environment
Python v3.9.13
Pyright 1.1.357
attrs 23.1.0
The code at official document of attrs library make the pyright type checker casue reportAttributeAccessIssue
- Code
from attrs import define, field
@define
class C:
x: int = field()
@x.validator
def _check_x(self, attribute, value):
if value > 42:
raise ValueError("x must be smaller or equal to 42")
- Result of pyright
qwer.py:8:8 - error: Cannot access member "validator" for type "int"
Member "validator" is unknown (reportAttributeAccessIssue)
1 error, 0 warnings, 0 informations
Instead of ignoring the issue, is there any way to resolve it?
pydantic
for class validation? It is one the most convenient libraries for validation.@x.validator
and replacing it withx: int = field(validator=[self. _check_x])