Advertisement
Guest User

Untitled

a guest
Dec 27th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4.  
  5. class SchemaBase:
  6. def __init__(self, *args, **kwargs):
  7. print('calling base init')
  8. super().__init__(*args, **kwargs)
  9.  
  10. class SchemaMeta(type):
  11. # not sure what the metaclass is for
  12. pass
  13.  
  14. def schema(cls):
  15. class tmp(SchemaBase, cls, metaclass=SchemaMeta):
  16. pass
  17. return tmp
  18.  
  19.  
  20. class A(object):
  21. def __init__(self, *args, **kwargs):
  22. print('calling A init')
  23. super().__init__()
  24.  
  25. def foo(self):
  26. pass
  27.  
  28.  
  29. class B(object):
  30. def __init__(self, *args, **kwargs):
  31. print('calling B init')
  32. super().__init__()
  33.  
  34. def baz(self):
  35. pass
  36.  
  37.  
  38. @schema
  39. class T(A, B):
  40. a = 1
  41. b = 2
  42. c = 3
  43.  
  44. def __init__(self, *args, **kwargs):
  45. print(self)
  46. super().__init__(*args, **kwargs)
  47. print('calling T init')
  48. self.__dict__.update(kwargs)
  49.  
  50. def bar(self):
  51. pass
  52.  
  53. a = T(a=10, b=11, x=1)
  54. b = T(a=20, c=22, y=2)
  55. c = T(b=31, c=32)
  56.  
  57. print(dir(T))
  58. print(dir(a))
  59. print(dir(b))
  60. print(dir(c))
  61.  
  62. print(id(a), id(b), id(c))
  63.  
  64. print(T)
  65. print(a.a)
  66. print(b.a)
  67. print(c.a)
  68. print(T, a.a, b.a, c.a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement