Skip to content

Instantly share code, notes, and snippets.

@tseaver
Created January 9, 2014 16:18
Show Gist options
  • Save tseaver/8336917 to your computer and use it in GitHub Desktop.
Save tseaver/8336917 to your computer and use it in GitHub Desktop.
Demonstrate https://github.com/zopefoundation/persistent/issues/3. The first file shows that persistent.mapping.PersistentMapping does *not* call its base class '__init__()' via 'super()'; the second shows that persistent.Persistent does.
from persistent.mapping import PersistentMapping
class Base1(object):
def __init__(self):
super(Base1, self).__init__()
print('Base1')
class Base2(object):
def __init__(self):
super(Base2, self).__init__()
print('Base2')
class Base3(PersistentMapping):
def __init__(self):
super(Base3, self).__init__()
print('Base3')
class Foo(PersistentMapping, Base1, Base2):
def __init__(self):
super(Foo, self).__init__()
class Bar(Base1, Base2, PersistentMapping):
def __init__(self):
super(Bar, self).__init__()
class Baz(PersistentMapping, Base1, Base2):
def __init__(self):
super(Baz, self).__init__()
print('Instantiating Foo')
print('-' * 50)
foo = Foo()
print('-' * 50)
print('Instantiating Bar')
print('-' * 50)
bar = Bar()
print('-' * 50)
print('Instantiating Baz')
print('-' * 50)
bar = Baz()
print('-' * 50)
from persistent import Persistent
class Base1(object):
def __init__(self):
super(Base1, self).__init__()
print('Base1')
class Base2(object):
def __init__(self):
super(Base2, self).__init__()
print('Base2')
class Base3(Persistent):
def __init__(self):
super(Base3, self).__init__()
print('Base3')
class Foo(Persistent, Base1, Base2):
def __init__(self):
super(Foo, self).__init__()
class Bar(Base1, Base2, Persistent):
def __init__(self):
super(Bar, self).__init__()
class Baz(Persistent, Base1, Base2):
def __init__(self):
super(Baz, self).__init__()
print('Instantiating Foo')
print('-' * 50)
foo = Foo()
print('-' * 50)
print('Instantiating Bar')
print('-' * 50)
bar = Bar()
print('-' * 50)
print('Instantiating Baz')
print('-' * 50)
bar = Baz()
print('-' * 50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment