File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -1504,20 +1504,19 @@ Most :meth:`__setattr__` implementations must modify ``self.__dict__`` to store
15041504local state for self without causing an infinite recursion.
15051505
15061506
1507- How do I call a method defined in a base class from a derived class that overrides it?
1508- --------------------------------------------------------------------------------------
1507+ How do I call a method defined in a base class from a derived class that extends it?
1508+ ------------------------------------------------------------------------------------
15091509
15101510Use the built-in :func: `super ` function::
15111511
15121512 class Derived(Base):
15131513 def meth(self):
1514- super(Derived, self ).meth()
1514+ super().meth() # calls Base.meth
15151515
1516- For version prior to 3.0, you may be using classic classes: For a class
1517- definition such as ``class Derived(Base): ... `` you can call method ``meth() ``
1518- defined in ``Base `` (or one of ``Base ``'s base classes) as ``Base.meth(self,
1519- arguments...) ``. Here, ``Base.meth `` is an unbound method, so you need to
1520- provide the ``self `` argument.
1516+ In the example, :func: `super ` will automatically determine the instance from
1517+ which it was called (the ``self `` value), look up the :term: `method resolution
1518+ order ` (MRO) with ``type(self).__mro__ ``, and return the next in line after
1519+ ``Derived `` in the MRO: ``Base ``.
15211520
15221521
15231522How can I organize my code to make it easier to change the base class?
You can’t perform that action at this time.
0 commit comments