abc.update_abstractmethods
Prev: abc.get_cache_token | Up: abc
Rel: abc.ABC, abc.ABCMeta, abc.abstractclassmethod, abc.abstractmethod
Ref: docs.python.org — abc.update_abstractmethods
Tags: #public #python3 #stdlib #abc
Import
import abc
from abc import update_abstractmethods
Signature & Overview
abc.update_abstractmethods(cls)
Recalculate the set of abstract methods of an abstract class.
Usage
from abc import ABC, abstractmethod, update_abstractmethods
def fill_area(cls):
cls.area = lambda self: 1.0
return update_abstractmethods(cls)
class Base(ABC):
@abstractmethod
def area(self) -> float: ...
@fill_area
class Unit(Base):
pass
assert Unit().area() == 1.0
Gotchas
- Requires Python 3.10+: Call in class decorators that dynamically synthesize implementations of abstract methods so
cls.__abstractmethods__is recalculated.
REPL Inspect
from abc import update_abstractmethods
help(update_abstractmethods)
Linked from
Related notes
- tuts/python3/stdlib_module/abc/get_cache_token Linked here; links to this page; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/ABC Linked here; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/ABCMeta Linked here; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/abstractclassmethod Linked here; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/abstractmethod Linked here; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/abc/abstractproperty shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/abstractstaticmethod shared tags: #abc, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib