Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- class SchemaBase:
- def __init__(self, *args, **kwargs):
- print('calling base init')
- super().__init__(*args, **kwargs)
- class SchemaMeta(type):
- # not sure what the metaclass is for
- pass
- def schema(cls):
- class tmp(SchemaBase, cls, metaclass=SchemaMeta):
- pass
- return tmp
- class A(object):
- def __init__(self, *args, **kwargs):
- print('calling A init')
- super().__init__()
- def foo(self):
- pass
- class B(object):
- def __init__(self, *args, **kwargs):
- print('calling B init')
- super().__init__()
- def baz(self):
- pass
- @schema
- class T(A, B):
- a = 1
- b = 2
- c = 3
- def __init__(self, *args, **kwargs):
- print(self)
- super().__init__(*args, **kwargs)
- print('calling T init')
- self.__dict__.update(kwargs)
- def bar(self):
- pass
- a = T(a=10, b=11, x=1)
- b = T(a=20, c=22, y=2)
- c = T(b=31, c=32)
- print(dir(T))
- print(dir(a))
- print(dir(b))
- print(dir(c))
- print(id(a), id(b), id(c))
- print(T)
- print(a.a)
- print(b.a)
- print(c.a)
- print(T, a.a, b.a, c.a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement