Skip to content

Instantly share code, notes, and snippets.

@arnsholt
Created June 2, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnsholt/a753bdbb8faf430a105b to your computer and use it in GitHub Desktop.
Save arnsholt/a753bdbb8faf430a105b to your computer and use it in GitHub Desktop.
__new__?
class C:
def __new__(cls, *args):
print("C.__new__")
return super().__new__(cls)
class D:
pass
C(1,2,3)
D(1,2,3)
# Outputs:
# C.__new__
# Traceback (most recent call last):
# File "test.py", line 9, in <module>
# D(1,2,3)
# TypeError: object() takes no parameters
class C:
def __new__(cls, *args):
print("C.__new__")
return super().__new__(cls)
class D:
pass
def __init__(self, a, b, c):
print("D.__init__")
C(1,2,3)
print("between")
D(1,2,3)
# Outputs:
# C.__new__
# between
# D.__init__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment