backport the magical zero-argument super() to python2
Project description
magicsuper: backport the magical zero-argument super() to python2
=================================================================
This is an (awful, hacky, wtf-were-you-thinking) attempt to port the magical
zero-argument super() call from python3 to python2.
In standard python2 usage of the super() builtin, you have to repeat both the
class and instance objects when you call super, like this:
class Hello(Base):
def hello(self):
super(Hello,self).hello()
Using magicsuper, you can get the friendlier behaviour from python3 where it
just figures out the correct call at runtime:
class Hello(Base):
def hello(self):
super().hello()
Of course, you can still explicitly pass in the arguments if you want to do
something strange. Sometimes you really do want that, e.g. to skip over
some classes in the method resolution order.
How does it work? By inspecting the calling frame to determine the function
object being executed and the object on which it's being called, and then
walking the object's __mro__ chain to find out where that function was
defined. Yuck, but it seems to work...
=================================================================
This is an (awful, hacky, wtf-were-you-thinking) attempt to port the magical
zero-argument super() call from python3 to python2.
In standard python2 usage of the super() builtin, you have to repeat both the
class and instance objects when you call super, like this:
class Hello(Base):
def hello(self):
super(Hello,self).hello()
Using magicsuper, you can get the friendlier behaviour from python3 where it
just figures out the correct call at runtime:
class Hello(Base):
def hello(self):
super().hello()
Of course, you can still explicitly pass in the arguments if you want to do
something strange. Sometimes you really do want that, e.g. to skip over
some classes in the method resolution order.
How does it work? By inspecting the calling frame to determine the function
object being executed and the object on which it's being called, and then
walking the object's __mro__ chain to find out where that function was
defined. Yuck, but it seems to work...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
magicsuper-0.2.0.tar.gz
(4.0 kB
view details)
File details
Details for the file magicsuper-0.2.0.tar.gz
.
File metadata
- Download URL: magicsuper-0.2.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71c663f61fbad5e3d2e2283da9912033a8bb23ba6b5f3c31e81ed18c607b440f |
|
MD5 | 85894a449df3ef473ec52b8c3f7f4e4a |
|
BLAKE2b-256 | f2e3213d0c37218e5edaf848dbda16ab22b63c5902313b428d61f27112a67c54 |