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

Attributes of frozen base classes can't be initialized #128

Closed
exarkun opened this issue Jan 3, 2017 · 1 comment
Closed

Attributes of frozen base classes can't be initialized #128

exarkun opened this issue Jan 3, 2017 · 1 comment
Milestone

Comments

@exarkun
Copy link

@exarkun exarkun commented Jan 3, 2017

Consider

import attr

@attr.s(frozen=True)
class Base(object):
    a = attr.ib()

@attr.s
class Derived(Base):
    b = attr.ib()


Derived("a", "b")

I would expect that this would instantiated aDerived instance and that its a attribute would be immutable and its b attribute would be mutable. Alternatively, perhaps it would be okay for b to be immutable as well (with the idea being that frozen-ness is inherited along with the rest). Not sure about this, but open to considering it.

Instead, the behavior is:

Traceback (most recent call last):
  File "frozenwhat.py", line 12, in <module>
    Derived("a", "b")
  File "<attrs generated init ceb0d1d1d54ce44d01f6dd968d2fb57e3b4d0016>", line 2, in __init__
  File "site-packages/attr/_make.py", line 201, in _frozen_setattrs
    raise FrozenInstanceError()
attr.exceptions.FrozenInstanceError

in other words, Derived instances can't be instantiated at all.

@hynek
Copy link
Member

@hynek hynek commented Jan 6, 2017

The problem here is that we currently don’t inherit frozen-ness.

@attr.s(frozen=True)
class Derived(Base):
    b = attr.ib()

works.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.