Skip to content

attrs: wrong type inferred from Factory attribute (using auto_attribs) #4341

Closed
@belm0

Description

@belm0

Steps to reproduce

attrs allows this form for factory, but pylint doesn't understand it:

import attr
from functools import partial
import numpy as np

@attr.attrs(auto_attribs=True)
class Foo:
    position: np.ndarray = attr.Factory(partial(np.zeros, 3))
    # position: np.ndarray = attr.attrib(default=attr.Factory(partial(np.zeros, 3)))  # this works

    def bar(self):
        return -self.position

Current behavior

 E1130: bad operand type for unary -: Factory (invalid-unary-operand-type)

Expected behavior

no error

pylint --version output

Result of pylint --version output:

pylint 2.7.2
astroid 2.5.1
Python 3.7.7 (default, Oct  5 2020, 09:18:33)
[Clang 9.0.0 (clang-900.0.39.2)]

Additional dependencies:

attrs=20.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🪲False Positive 🦟A message is emitted but nothing is wrong with the codeNeeds astroid Brain 🧠Needs a brain tip in astroid (then an astroid upgrade)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions