diff options
author | Andre Delfino <adelfino@gmail.com> | 2020-10-21 05:25:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-21 05:25:05 (GMT) |
commit | 4642ccd1c3e460cb2746d3f2095f1c1d1bafa4fe (patch) | |
tree | 6bc8e798fccbad52026576c422a51d8b25f1a58a | |
parent | c0f22fb8b3006936757cebb959cee94e285bc503 (diff) | |
download | cpython-4642ccd1c3e460cb2746d3f2095f1c1d1bafa4fe.zip cpython-4642ccd1c3e460cb2746d3f2095f1c1d1bafa4fe.tar.gz cpython-4642ccd1c3e460cb2746d3f2095f1c1d1bafa4fe.tar.bz2 |
Doc: Do not encourage using a base class name in a derived class (GH-22177)
-rw-r--r-- | Doc/faq/programming.rst | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 2d542cf..57ab3e2 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1517,18 +1517,18 @@ order` (MRO) with ``type(self).__mro__``, and return the next in line after 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? |