Skip to content

[3.9] Doc: Do not encourage using a base class name in a derived class (GH-22177) #22844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Doc/faq/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1518,18 +1518,18 @@ provide the ``self`` argument.
How can I organize my code to make it easier to change the base class?
----------------------------------------------------------------------

You could define an alias for the base class, assign the real base class to it
before your class definition, and use the alias throughout your class. Then all
You could assign the base class to an alias and derive from the alias. Then all
you have to change is the value assigned to the alias. Incidentally, this trick
is also handy if you want to decide dynamically (e.g. depending on availability
of resources) which base class to use. Example::

BaseAlias = <real base class>
class Base:
...

BaseAlias = Base

class Derived(BaseAlias):
def meth(self):
BaseAlias.meth(self)
...
...


How do I create static class data and static class methods?
Expand Down