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

frozen=True doesn't play well with converters #76

Closed
Deewiant opened this Issue Sep 5, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@Deewiant

Deewiant commented Sep 5, 2016

Code that I would expect to run without errors:

import attr

@attr.s(frozen=True)
class Ice:
    x = attr.ib(convert=lambda y: y + 1)

assert Ice(1).x == 2

Actual runtime result:

Traceback (most recent call last):
  File "asdf.py", line 7, in <module>
    assert Ice(1).x == 2
  File "<attrs generated init cd74cad05a4efad0b01528e489d51126583d23cb>", line 4, in __init__
  File "/usr/lib/python3.5/site-packages/attr/_make.py", line 483, in _convert
    setattr(inst, a.name, a.convert(getattr(inst, a.name)))
  File "/usr/lib/python3.5/site-packages/attr/_make.py", line 156, in _frozen_setattrs
    raise FrozenInstanceError()
attr.exceptions.FrozenInstanceError

Clearly _convert isn't aware of the class's frozenness. I took a quick peek at the code and it seems like it should perhaps be using _cached_setattr instead of the ordinary setattr?

@Tinche

This comment has been minimized.

Member

Tinche commented Sep 5, 2016

Roger, I can put together a fix in the evening.

@hynek hynek closed this in a624035 Sep 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment