[issue43243] Strict ABC classes

Yurii Karabas report at bugs.python.org
Wed Feb 17 13:35:04 EST 2021


Yurii Karabas <1998uriyyo at gmail.com> added the comment:

When I work with ABC classes usually I faced a problem -  I forget to implement one of the methods or make a typo in the method name. In such case I will know about it only when I will try to instantiate a class.

In case when a hierarchy is big you should go through classes and find the exact class where the problem is.

With this feature, in a case when a class inherits from strict ABC and doesn't implement all abstract methods of strict classes it will fail at class declaration rather than at instance creation as with regular ABC classes.

As an option, I can run mypy every time before start the python interpreter.

The perfect behavior for me is a case when ABC class will be strict by default, but it will break the existing code.

Examples to explain the idea:
```
from abc import ABC, abstractmethod

class Base(ABC):
    @abstraabstractmethod
    def foo(self):
         pass

class A(Base, ABC):  # totally okay, because class directly inherits from ABC
     pass

class B(Base):  # will fail, because class doesn't implement foo method
    pass
```

Raymond, could you please explain why the current behavior is default.

----------

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


More information about the Python-bugs-list mailing list