From 377a8bd23e20d6a240cb328aeb1bbbb328f87202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Wed, 9 Sep 2020 16:49:25 -0300 Subject: [PATCH 1/4] Use simpler super --- Doc/faq/programming.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 0731e92f6dbc60..851efcc3b67d30 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1525,7 +1525,7 @@ Use the built-in :func:`super` function:: class Derived(Base): def meth(self): - super(Derived, self).meth() + super().meth() # calls Base.meth For version prior to 3.0, you may be using classic classes: For a class definition such as ``class Derived(Base): ...`` you can call method ``meth()`` From 667472e1457d6e2589694e0bfc55575e9b3b7192 Mon Sep 17 00:00:00 2001 From: Andre Delfino Date: Fri, 18 Sep 2020 14:19:15 -0300 Subject: [PATCH 2/4] Update programming.rst --- Doc/faq/programming.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 851efcc3b67d30..bb30614b7f3bff 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1518,8 +1518,8 @@ Most :meth:`__setattr__` implementations must modify ``self.__dict__`` to store local state for self without causing an infinite recursion. -How do I call a method defined in a base class from a derived class that overrides it? --------------------------------------------------------------------------------------- +How do I call a method defined in a base class from a derived class that extends it? +------------------------------------------------------------------------------------ Use the built-in :func:`super` function:: From 48bce4ec4bbeee165463001bae195016805724cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Sat, 19 Sep 2020 22:41:37 -0300 Subject: [PATCH 3/4] Address Raymond's comment --- Doc/faq/programming.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 851efcc3b67d30..08f4b3a2d8602d 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1527,11 +1527,10 @@ Use the built-in :func:`super` function:: def meth(self): super().meth() # calls Base.meth -For version prior to 3.0, you may be using classic classes: For a class -definition such as ``class Derived(Base): ...`` you can call method ``meth()`` -defined in ``Base`` (or one of ``Base``'s base classes) as ``Base.meth(self, -arguments...)``. Here, ``Base.meth`` is an unbound method, so you need to -provide the ``self`` argument. +In the example, :func:`super` will automatically determine the instance from +which it was called (the ``self`` value), look up the :term:`method resolution +order` (MRO) of the instance type (``Derived``), and return the next in line +after ``Derived`` in the MRO: ``Base``. How can I organize my code to make it easier to change the base class? From 59809a49a102ad7a7ec5c38d29aa99c100404647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Sun, 20 Sep 2020 11:01:25 -0300 Subject: [PATCH 4/4] Address Raymond's comment --- Doc/faq/programming.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 4e4a31a8c95239..8478c232d04bf1 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1529,8 +1529,8 @@ Use the built-in :func:`super` function:: In the example, :func:`super` will automatically determine the instance from which it was called (the ``self`` value), look up the :term:`method resolution -order` (MRO) of the instance type (``Derived``), and return the next in line -after ``Derived`` in the MRO: ``Base``. +order` (MRO) with ``type(self).__mro__``, and return the next in line after +``Derived`` in the MRO: ``Base``. How can I organize my code to make it easier to change the base class?