Skip to content

Decorator API with auto_attribs=True doesn't work. #466

@ckutlu

Description

@ckutlu

When I try to use attribute decorators via auto attributes style, I get an error saying that the name doesn't exist. This doesn't happen if I initiate attributes with attr.ib(). Is this expected behavior?

Here is an example that fails:

@attr.s(auto_attribs=True)
class A:
    x: float

    @x.validator
    def _check_x(self, attrib, value):
        print("Validator called.")
        print(self, attrib, value)
a = A(5)

gives

Traceback (most recent call last):
  File "test.py", line 5, in first
    @attr.s(auto_attribs=True)
  File "test.py", line 9, in A
    @x.validator
NameError: name 'x' is not defined

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions