How common is the old Python 2-style super() syntax today?

0
0
Asked By MellowHarbor42 On

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?

4 Answers

Answered By QuietPebble8 On

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.

Answered By OrbitMango19 On

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.

Answered By CedarFox7 On

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.

Answered By VioletKite31 On

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.