pythonpython-typingpyrightpython-attrs

Pyright cause reportAttributeAccessIssue on attrs validator


The code at official document of attrs library make the pyright type checker casue reportAttributeAccessIssue

https://www.attrs.org/en/stable/init.html#validators

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")
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?


Solution

  • Pyright's support for attrs is, unfortunately, wildly inadequate. They took a hard stance on only supporting anything that gets standardized via PEPs for the new-ish "dataclass transform" API.