Skip to content

brain_attrs doesn't add PEP 526 instance variable annotations, causing no-member errors #2514

@Hnasar

Description

@Hnasar

Steps to reproduce

In some contexts, Pylint issues a false positive with an attrs class with only a type annotation (see PEP 526. If we add the attribute via the astroid brain_attrs then this fixes the issue. (I'm not sure if this is a duplicate of #724 ). This is supported at runtime with the newer attrs decorators.

# pylint: disable=missing-docstring,too-few-public-methods,unnecessary-lambda-assignment
import attrs  # pylint: disable=import-error

@attrs.define
class AttrsCls:
    x: int

ac = AttrsCls(1)
ac.x += 1

Current behavior

regression_xxxx_attrs_no_member.py:13: [E1101(no-member), ] Instance of 'AttrsCls' has no 'x' member

Expected behavior

No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions