From: Miss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 21 Oct 2020 08:11:13 +0000 (-0700) Subject: Doc: Do not encourage using a base class name in a derived class (GH-22177) X-Git-Tag: v3.9.1rc1~127 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f72101bb62d587bfe6c74cc9dd302a354520e964;p=thirdparty%2FPython%2Fcpython.git Doc: Do not encourage using a base class name in a derived class (GH-22177) (cherry picked from commit 4642ccd1c3e460cb2746d3f2095f1c1d1bafa4fe) Co-authored-by: Andre Delfino --- diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 106450fb7867..1d1155953e12 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -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 = + class Base: + ... + + BaseAlias = Base class Derived(BaseAlias): - def meth(self): - BaseAlias.meth(self) - ... + ... How do I create static class data and static class methods?