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
I am looking at the upcoming new
evolvefeature, but I found a bug in the error handling of that function when a validator raises an exception:which gives
which is obviously not true. Looking at the error handling in
evolve, I think it is too dangerous to assume the reason forTypeErrorlike it does. There is a lazy solution to this I will explain in a PR, but there may be better options