Skip to content

Wrong error message when using evolve #175

@cournape

Description

@cournape

I am looking at the upcoming new evolve feature, but I found a bug in the error handling of that function when a validator raises an exception:

from attr import evolve, attributes, attr
from attr.validators import instance_of

@attributes
class Foo(object):
    bar = attr(validator=instance_of(int))

foo1 = Foo(1)
foo2 = evolve(foo1, bar="2")

which gives

Traceback (most recent call last):
  File "attr-bug.py", line 9, in <module>
    foo2 = evolve(foo1, bar="2")
  File "/home/cournape/src/python/attrs/src/attr/_funcs.py", line 221, in evolve
    "{k} is not an attrs attribute on {cl}.".format(k=k, cl=cls))
attr.exceptions.AttrsAttributeNotFoundError: bar is not an attrs attribute on <class '__main__.Foo'>.

which is obviously not true. Looking at the error handling in evolve, I think it is too dangerous to assume the reason for TypeError like it does. There is a lazy solution to this I will explain in a PR, but there may be better options

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions