Last active
July 2, 2016 15:08
-
-
Save lsloan/cdfa7953c231b3283c88 to your computer and use it in GitHub Desktop.
Python: A basic implementation of `__new__()` that invokes the same method in the superclass.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Whenever I want to implement my own __new__() for a class, I've usually forgotten | |
the incantation for calling the method in the superclass, so I'm making note of it | |
here. | |
""" | |
class Fubar(object): | |
def __new__(cls, *args, **kwargs): | |
""" | |
To use, replace `Fubar` in the call to `super()` with the name of this class. | |
""" | |
instance = super(Fubar, cls).__new__(cls, *args, **kwargs) | |
# You code here... | |
return instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment