Skip to content

Instantly share code, notes, and snippets.

@jsocol
Created July 20, 2015 21:00
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 jsocol/226fa155677a682929f4 to your computer and use it in GitHub Desktop.
Save jsocol/226fa155677a682929f4 to your computer and use it in GitHub Desktop.
why new-style classes?
>>> class NewStyle(object):
... def foo(self):
... return 'foo'
>>> class OldStyle():
... def foo(self):
... return 'foo'
>>> dir(NewStyle)
['__class__',
'__delattr__',
'__dict__',
'__doc__',
'__format__',
'__getattribute__',
'__hash__',
'__init__',
'__module__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'foo']
>>> dir(OldStyle)
['__doc__', '__module__', 'foo']
>>> n = NewStyle()
>>> o = OldStyle()
>>> type(n)
__main__.NewStyle
>>> type(o)
instance
>>> class OldChild(OldStyle):
... def foo(self):
... return super(OldChild, self).foo() + 'bar'
>>> oc = OldChild()
>>> oc.foo()
TypeError: must be type, not classobj
@jsocol
Copy link
Author

jsocol commented Jul 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment