Skip to content

assoc bypasses validators ? #169

Closed
Closed
@cournape

Description

@cournape

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 ?

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