[issue44905] Abstract instance and class attributes for abstract base classes

Alex Waygood report at bugs.python.org
Mon Aug 16 07:07:55 EDT 2021


Alex Waygood <Alex.Waygood at Gmail.com> added the comment:

Tomasz -- as discussed in the original BPO issue for `abstractmethod` implementations (https://bugs.python.org/issue1706989), this works as a workaround:

```
>>> from abc import ABCMeta
>>> class AbstractAttribute:
... 	__isabstractmethod__ = True
... 	
>>> class Foo(metaclass=ABCMeta):
... 	abstract_attribute_to_be_overriden = AbstractAttribute()
... 	
>>> class Bar(Foo): pass
... 
>>> b = Bar()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: Can't instantiate abstract class Bar with abstract method abstract_attribute_to_be_overriden
```

It would be nice to have something like this in the `abc` module, though.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44905>
_______________________________________


More information about the Python-bugs-list mailing list