ABC with abstractmethod: kwargs on Base, explicit names on implementation

Dieter Maurer dieter at handshake.de
Thu Aug 27 13:51:13 EDT 2020


Samuel Marks wrote at 2020-8-27 15:58 +1000:
>The main thing I want is type safety. I want Python to complain if the
>callee uses the wrong argument types, and to provide suggestions on
>what's needed and info about it.
>
>Without a base class I can just have docstrings and type annotations
>to achieve that.
>
>What can I use that will require all implementers to have a minimum of
>the same properties and arguments, but also allow them to add new
>properties and arguments?

A main paradigm of object oriented programming is the
ability to use a derived class instance with knowledge only
about the base class. This implies that in many cases, you
need not know the concrete class because any instance of a derived
class must have the essential behavior of the base class instances.

This paradigm imposes limitations on the allowable signature changes.
An overriding method may add further parameters but all those
must have default values - otherwise, the use with base class knowledge
only would cause errors.

> Preferably I would like this all to happen before compile/interpret
time.

Use a "lint" version to check compatibilty.


More information about the Python-list mailing list