Advertisement
Guest User

Python MRO logging

a guest
Sep 12th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. class Meta(type):
  2.     def mro(self):
  3.         print("! Computing MRO")
  4.         return super().mro()
  5.  
  6. class Foo:
  7.     x = 'foo'
  8.  
  9. class Bar:
  10.     x = 'bar'
  11.  
  12. print("Defining Baz")
  13.  
  14. class Baz(Foo, metaclass=Meta):
  15.     pass
  16.  
  17. print("Instantiating Baz")
  18. b = Baz()
  19. print("Accessing attribute")
  20. b.x
  21. print("Changing Baz's bases")
  22. Baz.__bases__ = (Bar,)
  23. print("Accessing attribute")
  24. b.x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement