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

frozen class is made immutable before __attrs_post_init__ gets a turn #147

Closed
wsanchez opened this issue Feb 17, 2017 · 3 comments
Closed

Comments

@wsanchez
Copy link

This code:

from attr import attrib, attrs

@attrs(frozen=True)
class Foo(object):
    def __attrs_post_init__(self):
        self._thing = object()

Foo()

Raises FrozenInstanceError:

wsanchez$ python /tmp/foo.py
Traceback (most recent call last):
  File "/tmp/foo.py", line 8, in <module>
    Foo()
  File "<attrs generated init 97d170e1550eee4afc0af065b78cda302a97674c>", line 3, in __init__
  File "/tmp/foo.py", line 6, in __attrs_post_init__
    self._thing = object()
  File "/.../attr/_make.py", line 201, in _frozen_setattrs
    raise FrozenInstanceError()
attr.exceptions.FrozenInstanceError

It would be nice if __attrs_post_init__ can set attributes before the object is frozen.

@wsanchez
Copy link
Author

Ref #111

@hynek
Copy link
Member

hynek commented Feb 17, 2017

I believe this is a dupe of #120.

The problem is as I explained there that the object never actually is unfrozen. We just work around the frozen-ness. Would any of the ideas in the other issue there suite you?

@wsanchez
Copy link
Author

Yes that looks like a dup, thanks.

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

No branches or pull requests

2 participants