[New-bugs-announce] [issue43243] Strict ABC classes

Yurii Karabas report at bugs.python.org
Wed Feb 17 12:28:12 EST 2021

New submission from Yurii Karabas <1998uriyyo at gmail.com>:

Basically, the idea is to add the ability to mark abstract classes as strict.

What does this mean - in case when a class inherits from a strict abstract base class and doesn't implement all abstract methods then it will fail to create a class.

For instance:
>>> class Iterable(ABC, strict=True):
...   @abstractmethod
...   def __iter__(self):
...      pass

>>> class MyClass(Iterable):
...   pass
TypeError: Can't create class MyClass with unimplemented strict abstract method __iter__

That allows creating abc classes and be sure that class defines a required method, it will be perfrormed on a class declaration stage rather than class instance creation.

components: Library (Lib)
messages: 387169
nosy: uriyyo
priority: normal
severity: normal
status: open
title: Strict ABC classes
type: enhancement
versions: Python 3.10

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list