File tree 1 file changed +7
-8
lines changed
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
1504
1504
local state for self without causing an infinite recursion.
1505
1505
1506
1506
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
+ ------------------------------------------------------------------------------------
1509
1509
1510
1510
Use the built-in :func: `super ` function::
1511
1511
1512
1512
class Derived(Base):
1513
1513
def meth(self):
1514
- super(Derived, self ).meth()
1514
+ super().meth() # calls Base.meth
1515
1515
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 ``.
1521
1520
1522
1521
1523
1522
How 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