cirossmonteiro

Leaking private methods

Jun 19th, 2022 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. from anchor_class import Anchor, leak_private_methods
  2.  
  3.  
  4. class First(Anchor):
  5.     def __init__(self, value):
  6.         self.value = value
  7.  
  8.     def __increment(self):
  9.         """
  10.        THIS METHOD IS PRIVATE
  11.        """
  12.         self.value += 1
  13.  
  14. # First's increment method is private and increase First.value by 1
  15. Second = leak_private_methods(First)
  16.  
  17. # now First's increment method is public.
  18. instance = Second(0)
  19.  
  20. # initial value of First.value has been set to 0
  21. instance.increment()
  22.  
  23. # First.increment has been called and First.value has been incremented
  24. print(f'Worked: {instance.value == 1}')
  25.  
  26.  
Add Comment
Please, Sign In to add comment