Abstract property can't be found by mixins when property is a `attr.ib`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start by running the provided Python reproducer using @attr.s, attr.ib, ABC, and abstract property inheritance. Trace why C() remains abstract when B provides prop, and verify that the corrected behavior allows C() to instantiate and resolve prop to 5 without breaking the dataclass comparison case.
Written by the indexing model from the issue text.
Description
Same context here
The following runs fine:
from abc import ABC, abstractmethod
import attr
class A(ABC):
@abstractmethod
def prop(self):
pass
def foo(self):
print(self.prop())
class B:
def prop(self):
return 5
class C(B, A):
pass
C()
Here, C has a function prop inherited from B which is found first in the MRO order so A wouldn't complain about its existence. I tried this with a dataclass as well:
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
class A(ABC):
@property
@abstractmethod
def prop(self):
pass
def foo(self):
print(self.prop())
@dataclass
class B:
prop: int = field(default=5)
class C(B, A):
pass
C()
However, this doesn't work with attr:
from abc import ABC, abstractmethod
import attr
@attr.s
class A(ABC):
@property
@abstractmethod
def prop(self):
pass
def foo(self):
print(self.prop())
@attr.s
class B:
prop: int = attr.ib(default=5)
@attr.s
class C(B, A):
pass
C()
Running it:
❯ python test.py
Traceback (most recent call last):
File "test_mro_abstract_property.py", line 22, in <module>
C()
TypeError: Can't instantiate abstract class C with abstract methods prop
Python version: 3.8.3, attrs version 22.1.0
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/attrs
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
python-attrs/attrs#1543 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1532 ·
All issues in python-attrs/attrs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100