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

Using slots class overrides custom __setattr__ in 20.1.0 #680

Closed
pganssle opened this issue Aug 31, 2020 · 1 comment · Fixed by #681
Closed

Using slots class overrides custom __setattr__ in 20.1.0 #680

pganssle opened this issue Aug 31, 2020 · 1 comment · Fixed by #681
Labels

Comments

@pganssle
Copy link
Member

In 19.3.0, it was possible to have a custom __setattr__ on your slots class, but in 20.1.0 the custom __setattr__ is replaced with the default one:

import attr
@attr.s(slots=True)
class A:
    def __setattr__(self, key, value):
        print(f"{key}: {value}")

In 19.3.0:

>>> A().a = 3
a: 3

In 20.1.0:

>>> A().a = 3
AttributeError: 'A' object has no attribute 'a'
>>> A.__setattr__
<slot wrapper '__setattr__' of 'object' objects>

When slots=False, the same thing does not occur.

@hynek hynek added the Bug label Sep 1, 2020
hynek added a commit that referenced this issue Sep 1, 2020
Fixes #680

Signed-off-by: Hynek Schlawack <hs@ox.cx>
@hynek
Copy link
Member

hynek commented Sep 1, 2020

Now this is very embarrassing. Does #681 look good to you?

hynek added a commit that referenced this issue Sep 1, 2020
Fixes #680

Signed-off-by: Hynek Schlawack <hs@ox.cx>
hynek added a commit that referenced this issue Sep 1, 2020
Fixes #680

Signed-off-by: Hynek Schlawack <hs@ox.cx>
hynek added a commit that referenced this issue Sep 2, 2020
Fixes #680

Signed-off-by: Hynek Schlawack <hs@ox.cx>
hynek added a commit that referenced this issue Sep 3, 2020
Fixes #680

Signed-off-by: Hynek Schlawack <hs@ox.cx>
@hynek hynek closed this as completed in #681 Sep 5, 2020
hynek added a commit that referenced this issue Sep 5, 2020
* Don't reset custom __setattr__ in slotted classes

Fixes #680

Signed-off-by: Hynek Schlawack <hs@ox.cx>

* Simplify

Signed-off-by: Hynek Schlawack <hs@ox.cx>

* Be defensive about __bases__

Signed-off-by: Hynek Schlawack <hs@ox.cx>

* _Classes_ always have a __dict__

* Tighten xfail

* Clarify what need to be reset and when

Signed-off-by: Hynek Schlawack <hs@ox.cx>

* Reset __attrs_own_setattr__ along with __setattr__

Signed-off-by: Hynek Schlawack <hs@ox.cx>

* Update src/attr/_make.py

Co-authored-by: Paul Ganssle <paul@ganssle.io>

* Differentiate between own (= attrs) and custom (= user) __setattrs__

Signed-off-by: Hynek Schlawack <hs@ox.cx>

* We've always used __bases__ in our call to type()

So no reason for being defensive.

* Update tests/test_setattr.py

Co-authored-by: Paul Ganssle <paul@ganssle.io>

Co-authored-by: Paul Ganssle <paul@ganssle.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants