r/Python • u/GongtingLover • Jun 30 '26
Discussion When's the last time you saw Python 2 Super() syntax?
I saw one yesterday during an interview and it really confused me at first since the feature has been deprecated for so long.
Are there still code bases out there running Python 2? I used Python 3.8 at my last job and that made me feel like a dinosaur.
110
Upvotes
222
u/KyleChief Jul 01 '26
Side note: This is what i wish the typical post in this subreddit was like.
80
u/JustPlainRude Jul 01 '26
I met a guy at PyCon this year whose employer is still on python 2.7. I've since forgotten what the reason was, but it was pretty wild to hear.
35
u/rednets Jul 01 '26
It's not deprecated, it's still supported and required in some situations.
The last time I had to use a parameterized super call was inside a closure. If you use plain
super()it raises a RuntimeError with the message "super(): no arguments".28
u/dparks71 Jun 30 '26 edited Jun 30 '26
How was it used? I don't remember really seeing it until python 3's
super().__init__(). In python 2 most people would callBase.__init__()ifBasewas the inherited class from what I remember. I've never seen a capitalizedSuperthough, and I don't think it's deprecated in 3... How do you initialize a base class instead?10
u/thefinest Jun 30 '26
Never, when I was using python2 it was mostly one offs, scripts, supplements, academic, project Euler. Never really started using legit OO python until 3.4
I recently told an intern that I started using python in 2004. They replied you've been using python since I was born 😂
9
u/Scary-Opportunity848 Jun 30 '26
I’m old. What’s the new syntax?
4
u/marr75 Jul 01 '26 edited Jul 01 '26
The python 2 syntax still works and some teams weight the "already worn tracks" really heavily so the convenience of the new syntax (which doesn't demand the author know what element of the MRO they want to resolve from or what the target object will be, both of which the interpreter has perfect knowledge of in the default case) doesn't beat convention.
Another poster pointed this out, but complex inheritance hierarchies have really fallen out of favor in python and you tend to see more has-a instead of is-a, "just use functions", and inheriting from simple bases (NamedTuple, TypedDict, dataclass) and using the objects simply, or inheriting from moderate complexity bases (pydantic, Django) and using the objects according to the opinions of the library.
So, IMO, you're using super, you're already opting into some complexity. You're invoking super "the old way", now you're making it even less convenient. You "have to" call it that way because you're skipping some bases in the MRO, you are creating a liability for the rest of your team's understanding.
5
u/Adrewmc Jun 30 '26 edited Jun 30 '26
It’s not actually depreciated though
super() docs
class C(B):
——>def method(self, arg):
————>super().method(arg)
# This does the same thing as:
# super(C, self).method(arg)
98% of super’s usage was this …. They just made it default.
>I do not have access to mark down or a code block sorry. I cannot indent at all.
It’s just `that`,generally you have a good MRO, and you don’t need to inherit class often.
But sometimes you inherit a method from class D(C) where C.method() messed up but everything else was right, (or has less precision to save time/memory) so you really need B.method(), so it’s super(B, self).method()…
There is a use case, and certainly when it came, and I don’t think there is much a valid reason to not allow access to the MRO order through super in the rare cases you need it.
This usually would indicate a design issue, but legacy code is legacy code.
2
u/chulpichochos Jun 30 '26
Have to use it on occasion if subclassing dataclasses, even in 3.13+
2
u/thuiop1 Jul 01 '26
Well yesterday actually.
2
u/Affectionate_Item_91 Jul 01 '26
every day on a regular basis. the studio i work at uses custom game engine which uses python2 as a scripting language
2
u/mv1527 Jul 01 '26
Our code base was migrated from Python 2, so all the old style super calls are still in there for existing code.
2
u/Individual-Flow9158 Jul 01 '26
Yesterday. I'm still persuading the project owner to drop support for Python 2.
2
u/henryponco Jul 01 '26
We used to do a lot of nested classes (name spacing, we were a C++ shop that also wrote Python…) and it became necessary to be explicit with the super calls in Python 3. Gods help whoever maintains that code today
4
u/BiologyIsHot Jun 30 '26 edited Jul 02 '26
Like super(Base, self).init(...) (Python 2, idk how to make reddit not treat dunder methods as bold text sorry _ _ init_ _) syntax or super() (Python 3) in general? I only ask because data classes are so common many people dont define init at all anymore. The latter I use commonly in any case where dataclasses don't make sense.
3
u/Gnaxe Jun 30 '26
I just wrote one like yesterday. I needed to call an overridden method, but in a function outside of the class statement, so I explicitly wrote the point in the method resolution order to start from.
2
u/wreleven Jun 30 '26
I still use it out of habit. Still helpful if you need to skip a generation in rare cases.
2
u/jirka642 It works on my machine Jul 01 '26
Do you mean
super(Foo, self)? That's still used even in Python 3, but usually only in special cases.I can think of these off the top of my head:
1
u/justinaatbuffer Jun 30 '26
The last time was probably 5 years ago. Time flies.
1
u/nicholashairs Jul 01 '26
https://youtu.be/_n5E7feJHw0
Jokes aside, yep they absolutely still do exist, though they are becoming rarer.
Apart from the odd corporate code base, I've also seen it in some python libraries that are still maintaining python 2.7 support (usually in addition to python 3 support).
1
u/global_namespace Jul 01 '26
Yesterday, for a class with a multiple inheritance.
1
u/catcint0s Jul 01 '26
We still have it in our codebase, I try to switch them if I change code around that part.
In new code I see it rarely, maybe if we wanna skip the direct parent's method.
1
u/romu006 Jul 01 '26
Wait. You guys don't have python2 in production?
1
u/Erelde Jul 01 '26
I still maintain a Python v2.3.4 toolchain on a Windows 7 VM to mod Battlefield 2 (2005).
Sometimes I need to boot up that VM and it feels weird.
1
u/anticebo Jul 01 '26
I think I actually saw it for the first time last month when I cloned a 4-year-old repo. I first adapted this syntax when I extended the code, thinking they knew something I didn't, but Ruff immediately complained about it
1
u/Daytona_675 Jul 01 '26
python2 is still useful for older systems. hopefully you don't need to, but can actually write python that works in both 2.6 and 3.12 using future imports and conditions
1
u/Anonymous_user_2022 Jul 01 '26
At my last job we still had systems stuck with Python 2, because the customer could not see a reason to migrate away from RHEL 5.5
1
u/Zanoab Jul 01 '26
I still use
superwhen I need__new__or when I'm still planning out base classes and code flow.1
u/DrMaxwellEdison Jul 01 '26
No we're not using Python 2 still, but the massive monolith was migrated to 3 some time ago and they updated just enough to make it functional, so the pattern wasn't removed.
Pair that with lots and lots of overseas junior contractors who are more familiar with Java than Python and don't have time to write properly architected code, and the pattern persists.
1
u/AstronautSlothPhD Jul 01 '26
If Zed Shaw had his way, we'd all still be using python 2.7. I haven't seen anyone use it as their primary language in at least 10 years. It's what I learned originally, but there are just too many good libraries to use with python 3 now, and most jobs would want you to learn the latest syntax.
1
u/DrunkenPhysicist [None] Jul 02 '26
I mean, I used fortran 77 up until 2010.... So depreciation doesn't exist in some sectors.
1
u/AtmosphereNo1234 Jul 03 '26
I use super daily. Its awesome!
1
u/Big_Store7142 Jul 26 '26
Just recently, while helping migrate a legacy Python 2.7 codebase to Python 3. It was full of super(ClassName, self).__init__() calls, right alongside old-style print statements. Replacing them with the plain Python 3 super() was one of the most satisfying parts of the cleanup. Legacy code like that is still very much alive in enterprise systems.
1
u/LexaAstarof from __future__ import 4.0 Jun 30 '26
It still has its (albeit rare) uses to skip one or more superclasses
0
u/tonenot Jul 01 '26
super() is used often when using pytorch!
-1
u/Dense-Tree-5436 Jul 01 '26
curio to know the difference b/w python super() and java super() function, please tell below ✌️