Wield Python's super() like a Jedi
rhettinger.wordpress.com
Wield Python's super() like a Jedi
1–10 of 67 posts
Re: Wield Python's super() like a Jedi
#2Re: Wield Python's super() like a Jedi
#3Re: Wield Python's super() like a Jedi
#4Have to deal with enough languages as it is. Don't want to further add to my brain mess by learning Python 3 syntax just yet.
Here's a link to the Python 2 version of the examples: http://code.activestate.com/recipes/577721-how-to-use-super-...
Re: Wield Python's super() like a Jedi
#5Re: Wield Python's super() like a Jedi
#6Re: Wield Python's super() like a Jedi
#7how does the runtime performance of super() compare to the hardcoding method? (from your example, using dict.__setitem__ as opposed to super().__setitem__ )
Re: Wield Python's super() like a Jedi
#8how does the runtime performance of super() compare to the hardcoding method? (from your example, using dict.__setitem__ as opposed to super().__setitem__ )
I don't think it suffers much as the method resolution order (mro) is computed ahead-of-time when creating the class.
"The calculation depends on both the class where super is called and on the instance’s tree of ancestors."
I agree that the class's MRO can be computed ahead of time, but theoretically the instance's order could be different (if a class method changed the definition of __setitem__)
Re: Wield Python's super() like a Jedi
#9Have to deal with enough languages as it is. Don't want to further add to my brain mess by learning Python 3 syntax just yet.
super() was introduced in Python2.2 many years ago. Everything in the article works with very old versions of Python. Here's a link to the Python 2 version of the examples: http://code.activestate.com/recipes/577721-how-to-use-super-...
Re: Wield Python's super() like a Jedi
#10how does the runtime performance of super() compare to the hardcoding method? (from your example, using dict.__setitem__ as opposed to super().__setitem__ )
Contrasting dict.__setitem__ with super().__setitem__, the latter adds one function call. In addition, both forms require a builtin lookup and an attribute lookup.
In PyPy, much of the overhead of builtin lookups, function calls, and attribute lookups is automatically optimized away.