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

attr.ib cleanup + auto_attribs + class vars from superclasses #427

Closed
hynek opened this issue Aug 20, 2018 · 1 comment
Closed

attr.ib cleanup + auto_attribs + class vars from superclasses #427

hynek opened this issue Aug 20, 2018 · 1 comment
Milestone

Comments

@hynek
Copy link
Member

hynek commented Aug 20, 2018

Consider the following:

import attr

class Base:
    x = 0

@attr.s(auto_attribs=True)
class C(Base):
    x: int

This raises an:

Traceback (most recent call last):
  File "t.py", line 9, in <module>
    class C(Base):
  File "/Users/hynek/Projects/attrs/src/attr/_make.py", line 858, in wrap
    return builder.build_class()
  File "/Users/hynek/Projects/attrs/src/attr/_make.py", line 496, in build_class
    return self._patch_original_class()
  File "/Users/hynek/Projects/attrs/src/attr/_make.py", line 514, in _patch_original_class
    delattr(cls, name)
AttributeError: x

(interestingly getattr(cls, name) works but delattr does not)

This is actually quite common if you implement an ABC. The current code is:

                if (
                    name not in super_names
                    and getattr(cls, name, None) is not None
                ):
                    delattr(cls, name)

Maybe we should change the check to isinstance(getattr(cls, name, None), _CountingAttr)?

@hynek
Copy link
Member Author

hynek commented Aug 20, 2018

(Maybe wrapping in try/except would be better.)

@hynek hynek mentioned this issue Aug 21, 2018
7 tasks
@hynek hynek added this to the 18.2 milestone Aug 21, 2018
hynek added a commit that referenced this issue Aug 27, 2018
* Allow to override class vars of super classes w/ annotations

Fixes #427

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

No branches or pull requests

1 participant