How common is the old Python 2-style super() syntax today?
Asked by
MellowHarbor42
I ran into an old-style super call during an interview yesterday and it threw me off: `super(ClassName, self).method()`. I had mostly used Python 3.8 recently, where the usual form is simply `super().method()`, so I assumed the older syntax had been deprecated for a long time. Are there still production codebases running Python 2, or is this mostly legacy syntax that survives after migrations to Python 3?
Answers
It also shows up in multiple-inheritance code. Unlike directly calling `BaseClass.__init__()`, `super()` follows the classโs method-resolution order, which lets cooperative inheritance work properly. That complexity is one reason many newer Python designs favor composition or simpler inheritance.
Reply to this answer
Python 2 itself has been unsupported for years, but plenty of old enterprise systems, internal tools, game engines, and customer environments still depend on it. The usual reasons are expensive migrations, old operating systems, vendor software, or code that has been stable enough that nobody wants to risk changing it.
Reply to this answer
The explicit form, `super(ClassName, self)`, is not deprecated in Python 3. The zero-argument `super()` is just the modern shorthand and handles the common case. The older form can still be useful when you need to specify a different starting point in the method-resolution order, use an object other than `self`, or deal with unusual metaprogramming.
Reply to this answer
A lot of migrated codebases still contain the old calls because teams changed just enough to make the Python 3 port work. Youโll often see them next to other historical patterns, even though new code generally uses `super()` without arguments.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions