Skip to content

Instantly share code, notes, and snippets.

@jfindlay
Created May 9, 2016 07:24
Show Gist options
  • Save jfindlay/889e4fca5af093d4cee2255cb2e140e7 to your computer and use it in GitHub Desktop.
Save jfindlay/889e4fca5af093d4cee2255cb2e140e7 to your computer and use it in GitHub Desktop.
  • Is it possible to get IntA.__new__ to return an object of type IntA without calling __new__ on the parent class?
  • Is this situation unique to integer or builtin types?
>>> class IntA(int):
...  def __new__(cls, i=0):
...   return i
...
>>> class IntB(int):
...  def __new__(cls, i=0):
...   return int.__new__(cls, i)
...
>>> type(IntA())
<class 'int'>
>>> type(IntB())
<class '__main__.IntB'>
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment