test_restricted.py 783 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. #
  3. # Author: Kirill Makhonin (@kirillmakhonin)
  4. # Copyright (c) 2008-2016 California Institute of Technology.
  5. # Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
  6. # License: 3-clause BSD. The full license text is available at:
  7. # - https://github.com/uqfoundation/dill/blob/master/LICENSE
  8. import dill
  9. class RestrictedType:
  10. def __bool__(*args, **kwargs):
  11. raise Exception('Restricted function')
  12. __eq__ = __lt__ = __le__ = __ne__ = __gt__ = __ge__ = __hash__ = __bool__
  13. glob_obj = RestrictedType()
  14. def restricted_func():
  15. a = glob_obj
  16. def test_function_with_restricted_object():
  17. deserialized = dill.loads(dill.dumps(restricted_func, recurse=True))
  18. if __name__ == '__main__':
  19. test_function_with_restricted_object()