Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assoc bypasses validators ? #169

Closed
cournape opened this issue Mar 23, 2017 · 1 comment
Closed

assoc bypasses validators ? #169

cournape opened this issue Mar 23, 2017 · 1 comment

Comments

@cournape
Copy link
Contributor

I was surprised by the following:

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


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


foo = Foo(1)
try:
    foo = Foo("1")
except TypeError:
    pass
else:
    raise ValueError()

try:
    foo2 = assoc(foo, a="1")
except TypeError:
    pass
else:
    raise ValueError("Could set Foo.a to a string value")

I would expect new instances set through assoc to go through validators. Is this a bug, or is it expected ?

@hynek
Copy link
Member

hynek commented Mar 23, 2017

Yeah assoc has a design problem so we're replacing it with attr.evolve. Check the CHANGELOG for PRs/issues. Mainly #135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants