Python super() not implemented
See original GitHub issueThe following code generates SyntaxError: super() is only valid in derived class constructors
class foo:
def bar(self):
print('bar')
class foo2(foo):
def bar(self):
print('bar2')
super().bar()
# foo.bar(self) # workaround
The error message seems to imply it works in derived constructors, but using it there generates the same error.
Issue Analytics
- State:
- Created 7 years ago
- Comments:21 (11 by maintainers)
Top Results From Across the Web
How is super() in Python 3 implemented? - Stack Overflow
This case is used for class methods; the return value is obj. - If it is an instance, it must be an instance...
Read more >Supercharge Your Classes With Python super()
Note: Technically, super() doesn't return a method. It returns a proxy object. This is an object that delegates calls to the correct class...
Read more >Python NotImplementedError | How to Avoid ... - eduCBA
Python NotImplementedError Exception occurs at runtime when client characterized base classes; conceptual techniques should raise this exception when they ...
Read more >Built-in Exceptions — Python 3.11.1 documentation
A list of the notes of this exception, which were added with add_note() . ... NotImplementedError and NotImplemented are not interchangeable, ...
Read more >Python's Super Considered Harmful - James Y. Knight
In addition to the above problems, there is a huge backwards-compatibility problem in that using super() does not mesh well at all with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll just note that as far as the DRYness of super() is concerned, that is trivially achieved, by aliasing
Now you only need to rename SomeClass in one place. Not to mention that with modern refactoring tools, renaming a class everywhere it is used is trivial to do, except in the very rare case of a codebase with lots of different classes all named with the exact same name.
Also IMO even using super() in the simple inheritance case is an antipattern, because it makes your code much less readable. Now someone reading through your sub-class has to remember what the super class is everytime they see super(), and there is no easy way to jump to the definition of the superclass without first going to the top of the sub class to get the name of the super class.
Basically, super() improves (marginally, over aliasing) maintainability for someone very familiar with the code, at the cost of readability for everyone else.
As ever: amazing turn around time!