Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- lib/python3.12/site-packages/dill/__pycache__/__diff.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/__info__.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/__init__.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/_objects.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/_shims.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/detect.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/logger.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/objtypes.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/pointers.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/session.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/settings.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/source.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/__pycache__/temp.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/__init__.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/__main__.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_abc.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_check.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_classdef.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_dataclasses.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_detect.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_dictviews.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_diff.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_extendpickle.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_fglobals.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_file.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_functions.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_functors.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_logger.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_mixins.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_module.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_moduledict.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_nested.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_objects.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_properties.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_pycapsule.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_recursive.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_registered.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_restricted.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_selected.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_session.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_source.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_temp.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/__pycache__/test_weakref.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/dill/tests/test_classdef.py +340 -0
- lib/python3.12/site-packages/dill/tests/test_extendpickle.py +53 -0
- lib/python3.12/site-packages/dill/tests/test_logger.py +70 -0
- lib/python3.12/site-packages/dill/tests/test_nested.py +135 -0
- lib/python3.12/site-packages/dill/tests/test_restricted.py +27 -0
- lib/python3.12/site-packages/dill/tests/test_source.py +154 -0
- lib/python3.12/site-packages/dill/tests/test_weakref.py +72 -0
lib/python3.12/site-packages/dill/__pycache__/__diff.cpython-312.pyc
ADDED
|
Binary file (8.98 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/__info__.cpython-312.pyc
ADDED
|
Binary file (10.7 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (4.73 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/_objects.cpython-312.pyc
ADDED
|
Binary file (25.7 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/_shims.cpython-312.pyc
ADDED
|
Binary file (7.68 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/detect.cpython-312.pyc
ADDED
|
Binary file (13.3 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/logger.cpython-312.pyc
ADDED
|
Binary file (12.6 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/objtypes.cpython-312.pyc
ADDED
|
Binary file (652 Bytes). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/pointers.cpython-312.pyc
ADDED
|
Binary file (4.96 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/session.cpython-312.pyc
ADDED
|
Binary file (26.3 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/settings.cpython-312.pyc
ADDED
|
Binary file (385 Bytes). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/source.cpython-312.pyc
ADDED
|
Binary file (40.7 kB). View file
|
|
|
lib/python3.12/site-packages/dill/__pycache__/temp.cpython-312.pyc
ADDED
|
Binary file (9.47 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (397 Bytes). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/__main__.cpython-312.pyc
ADDED
|
Binary file (1.31 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_abc.cpython-312.pyc
ADDED
|
Binary file (7.93 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_check.cpython-312.pyc
ADDED
|
Binary file (2.12 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_classdef.cpython-312.pyc
ADDED
|
Binary file (19.6 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_dataclasses.cpython-312.pyc
ADDED
|
Binary file (1.58 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_detect.cpython-312.pyc
ADDED
|
Binary file (7.56 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_dictviews.cpython-312.pyc
ADDED
|
Binary file (2.18 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_diff.cpython-312.pyc
ADDED
|
Binary file (3.51 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_extendpickle.cpython-312.pyc
ADDED
|
Binary file (2.2 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_fglobals.cpython-312.pyc
ADDED
|
Binary file (2.91 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_file.cpython-312.pyc
ADDED
|
Binary file (19.3 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_functions.cpython-312.pyc
ADDED
|
Binary file (7.12 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_functors.cpython-312.pyc
ADDED
|
Binary file (1.47 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_logger.cpython-312.pyc
ADDED
|
Binary file (3.65 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_mixins.cpython-312.pyc
ADDED
|
Binary file (6.92 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_module.cpython-312.pyc
ADDED
|
Binary file (3.19 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_moduledict.cpython-312.pyc
ADDED
|
Binary file (2.11 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_nested.cpython-312.pyc
ADDED
|
Binary file (6.3 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_objects.cpython-312.pyc
ADDED
|
Binary file (2.68 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_properties.cpython-312.pyc
ADDED
|
Binary file (2.44 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_pycapsule.cpython-312.pyc
ADDED
|
Binary file (2.06 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_recursive.cpython-312.pyc
ADDED
|
Binary file (8.85 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_registered.cpython-312.pyc
ADDED
|
Binary file (2.58 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_restricted.cpython-312.pyc
ADDED
|
Binary file (1.23 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_selected.cpython-312.pyc
ADDED
|
Binary file (5.92 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_session.cpython-312.pyc
ADDED
|
Binary file (14.4 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_source.cpython-312.pyc
ADDED
|
Binary file (8.81 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_temp.cpython-312.pyc
ADDED
|
Binary file (4.27 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/__pycache__/test_weakref.cpython-312.pyc
ADDED
|
Binary file (2.8 kB). View file
|
|
|
lib/python3.12/site-packages/dill/tests/test_classdef.py
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
| 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 |
+
|
| 9 |
+
import dill
|
| 10 |
+
from enum import EnumMeta
|
| 11 |
+
import sys
|
| 12 |
+
dill.settings['recurse'] = True
|
| 13 |
+
|
| 14 |
+
# test classdefs
|
| 15 |
+
class _class:
|
| 16 |
+
def _method(self):
|
| 17 |
+
pass
|
| 18 |
+
def ok(self):
|
| 19 |
+
return True
|
| 20 |
+
|
| 21 |
+
class _class2:
|
| 22 |
+
def __call__(self):
|
| 23 |
+
pass
|
| 24 |
+
def ok(self):
|
| 25 |
+
return True
|
| 26 |
+
|
| 27 |
+
class _newclass(object):
|
| 28 |
+
def _method(self):
|
| 29 |
+
pass
|
| 30 |
+
def ok(self):
|
| 31 |
+
return True
|
| 32 |
+
|
| 33 |
+
class _newclass2(object):
|
| 34 |
+
def __call__(self):
|
| 35 |
+
pass
|
| 36 |
+
def ok(self):
|
| 37 |
+
return True
|
| 38 |
+
|
| 39 |
+
class _meta(type):
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
def __call__(self):
|
| 43 |
+
pass
|
| 44 |
+
def ok(self):
|
| 45 |
+
return True
|
| 46 |
+
|
| 47 |
+
_mclass = _meta("_mclass", (object,), {"__call__": __call__, "ok": ok})
|
| 48 |
+
|
| 49 |
+
del __call__
|
| 50 |
+
del ok
|
| 51 |
+
|
| 52 |
+
o = _class()
|
| 53 |
+
oc = _class2()
|
| 54 |
+
n = _newclass()
|
| 55 |
+
nc = _newclass2()
|
| 56 |
+
m = _mclass()
|
| 57 |
+
|
| 58 |
+
if sys.hexversion < 0x03090000:
|
| 59 |
+
import typing
|
| 60 |
+
class customIntList(typing.List[int]):
|
| 61 |
+
pass
|
| 62 |
+
else:
|
| 63 |
+
class customIntList(list[int]):
|
| 64 |
+
pass
|
| 65 |
+
|
| 66 |
+
# test pickles for class instances
|
| 67 |
+
def test_class_instances():
|
| 68 |
+
assert dill.pickles(o)
|
| 69 |
+
assert dill.pickles(oc)
|
| 70 |
+
assert dill.pickles(n)
|
| 71 |
+
assert dill.pickles(nc)
|
| 72 |
+
assert dill.pickles(m)
|
| 73 |
+
|
| 74 |
+
def test_class_objects():
|
| 75 |
+
clslist = [_class,_class2,_newclass,_newclass2,_mclass]
|
| 76 |
+
objlist = [o,oc,n,nc,m]
|
| 77 |
+
_clslist = [dill.dumps(obj) for obj in clslist]
|
| 78 |
+
_objlist = [dill.dumps(obj) for obj in objlist]
|
| 79 |
+
|
| 80 |
+
for obj in clslist:
|
| 81 |
+
globals().pop(obj.__name__)
|
| 82 |
+
del clslist
|
| 83 |
+
for obj in ['o','oc','n','nc']:
|
| 84 |
+
globals().pop(obj)
|
| 85 |
+
del objlist
|
| 86 |
+
del obj
|
| 87 |
+
|
| 88 |
+
for obj,cls in zip(_objlist,_clslist):
|
| 89 |
+
_cls = dill.loads(cls)
|
| 90 |
+
_obj = dill.loads(obj)
|
| 91 |
+
assert _obj.ok()
|
| 92 |
+
assert _cls.ok(_cls())
|
| 93 |
+
if _cls.__name__ == "_mclass":
|
| 94 |
+
assert type(_cls).__name__ == "_meta"
|
| 95 |
+
|
| 96 |
+
# test NoneType
|
| 97 |
+
def test_specialtypes():
|
| 98 |
+
assert dill.pickles(type(None))
|
| 99 |
+
assert dill.pickles(type(NotImplemented))
|
| 100 |
+
assert dill.pickles(type(Ellipsis))
|
| 101 |
+
assert dill.pickles(type(EnumMeta))
|
| 102 |
+
|
| 103 |
+
from collections import namedtuple
|
| 104 |
+
Z = namedtuple("Z", ['a','b'])
|
| 105 |
+
Zi = Z(0,1)
|
| 106 |
+
X = namedtuple("Y", ['a','b'])
|
| 107 |
+
X.__name__ = "X"
|
| 108 |
+
X.__qualname__ = "X" #XXX: name must 'match' or fails to pickle
|
| 109 |
+
Xi = X(0,1)
|
| 110 |
+
Bad = namedtuple("FakeName", ['a','b'])
|
| 111 |
+
Badi = Bad(0,1)
|
| 112 |
+
Defaults = namedtuple('Defaults', ['x', 'y'], defaults=[1])
|
| 113 |
+
Defaultsi = Defaults(2)
|
| 114 |
+
|
| 115 |
+
# test namedtuple
|
| 116 |
+
def test_namedtuple():
|
| 117 |
+
assert Z is dill.loads(dill.dumps(Z))
|
| 118 |
+
assert Zi == dill.loads(dill.dumps(Zi))
|
| 119 |
+
assert X is dill.loads(dill.dumps(X))
|
| 120 |
+
assert Xi == dill.loads(dill.dumps(Xi))
|
| 121 |
+
assert Defaults is dill.loads(dill.dumps(Defaults))
|
| 122 |
+
assert Defaultsi == dill.loads(dill.dumps(Defaultsi))
|
| 123 |
+
assert Bad is not dill.loads(dill.dumps(Bad))
|
| 124 |
+
assert Bad._fields == dill.loads(dill.dumps(Bad))._fields
|
| 125 |
+
assert tuple(Badi) == tuple(dill.loads(dill.dumps(Badi)))
|
| 126 |
+
|
| 127 |
+
class A:
|
| 128 |
+
class B(namedtuple("C", ["one", "two"])):
|
| 129 |
+
'''docstring'''
|
| 130 |
+
B.__module__ = 'testing'
|
| 131 |
+
|
| 132 |
+
a = A()
|
| 133 |
+
assert dill.copy(a)
|
| 134 |
+
|
| 135 |
+
assert dill.copy(A.B).__name__ == 'B'
|
| 136 |
+
assert dill.copy(A.B).__qualname__.endswith('.<locals>.A.B')
|
| 137 |
+
assert dill.copy(A.B).__doc__ == 'docstring'
|
| 138 |
+
assert dill.copy(A.B).__module__ == 'testing'
|
| 139 |
+
|
| 140 |
+
from typing import NamedTuple
|
| 141 |
+
|
| 142 |
+
def A():
|
| 143 |
+
class B(NamedTuple):
|
| 144 |
+
x: int
|
| 145 |
+
return B
|
| 146 |
+
|
| 147 |
+
assert type(dill.copy(A()(8))).__qualname__ == type(A()(8)).__qualname__
|
| 148 |
+
|
| 149 |
+
def test_dtype():
|
| 150 |
+
try:
|
| 151 |
+
import numpy as np
|
| 152 |
+
|
| 153 |
+
dti = np.dtype('int')
|
| 154 |
+
assert np.dtype == dill.copy(np.dtype)
|
| 155 |
+
assert dti == dill.copy(dti)
|
| 156 |
+
except ImportError: pass
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def test_array_nested():
|
| 160 |
+
try:
|
| 161 |
+
import numpy as np
|
| 162 |
+
|
| 163 |
+
x = np.array([1])
|
| 164 |
+
y = (x,)
|
| 165 |
+
assert y == dill.copy(y)
|
| 166 |
+
|
| 167 |
+
except ImportError: pass
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def test_array_subclass():
|
| 171 |
+
try:
|
| 172 |
+
import numpy as np
|
| 173 |
+
|
| 174 |
+
class TestArray(np.ndarray):
|
| 175 |
+
def __new__(cls, input_array, color):
|
| 176 |
+
obj = np.asarray(input_array).view(cls)
|
| 177 |
+
obj.color = color
|
| 178 |
+
return obj
|
| 179 |
+
def __array_finalize__(self, obj):
|
| 180 |
+
if obj is None:
|
| 181 |
+
return
|
| 182 |
+
if isinstance(obj, type(self)):
|
| 183 |
+
self.color = obj.color
|
| 184 |
+
def __getnewargs__(self):
|
| 185 |
+
return np.asarray(self), self.color
|
| 186 |
+
|
| 187 |
+
a1 = TestArray(np.zeros(100), color='green')
|
| 188 |
+
if not dill._dill.IS_PYPY:
|
| 189 |
+
assert dill.pickles(a1)
|
| 190 |
+
assert a1.__dict__ == dill.copy(a1).__dict__
|
| 191 |
+
|
| 192 |
+
a2 = a1[0:9]
|
| 193 |
+
if not dill._dill.IS_PYPY:
|
| 194 |
+
assert dill.pickles(a2)
|
| 195 |
+
assert a2.__dict__ == dill.copy(a2).__dict__
|
| 196 |
+
|
| 197 |
+
class TestArray2(np.ndarray):
|
| 198 |
+
color = 'blue'
|
| 199 |
+
|
| 200 |
+
a3 = TestArray2([1,2,3,4,5])
|
| 201 |
+
a3.color = 'green'
|
| 202 |
+
if not dill._dill.IS_PYPY:
|
| 203 |
+
assert dill.pickles(a3)
|
| 204 |
+
assert a3.__dict__ == dill.copy(a3).__dict__
|
| 205 |
+
|
| 206 |
+
except ImportError: pass
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
def test_method_decorator():
|
| 210 |
+
class A(object):
|
| 211 |
+
@classmethod
|
| 212 |
+
def test(cls):
|
| 213 |
+
pass
|
| 214 |
+
|
| 215 |
+
a = A()
|
| 216 |
+
|
| 217 |
+
res = dill.dumps(a)
|
| 218 |
+
new_obj = dill.loads(res)
|
| 219 |
+
new_obj.__class__.test()
|
| 220 |
+
|
| 221 |
+
# test slots
|
| 222 |
+
class Y(object):
|
| 223 |
+
__slots__ = ('y', '__weakref__')
|
| 224 |
+
def __init__(self, y):
|
| 225 |
+
self.y = y
|
| 226 |
+
|
| 227 |
+
value = 123
|
| 228 |
+
y = Y(value)
|
| 229 |
+
|
| 230 |
+
class Y2(object):
|
| 231 |
+
__slots__ = 'y'
|
| 232 |
+
def __init__(self, y):
|
| 233 |
+
self.y = y
|
| 234 |
+
|
| 235 |
+
def test_slots():
|
| 236 |
+
assert dill.pickles(Y)
|
| 237 |
+
assert dill.pickles(y)
|
| 238 |
+
assert dill.pickles(Y.y)
|
| 239 |
+
assert dill.copy(y).y == value
|
| 240 |
+
assert dill.copy(Y2(value)).y == value
|
| 241 |
+
|
| 242 |
+
def test_origbases():
|
| 243 |
+
assert dill.copy(customIntList).__orig_bases__ == customIntList.__orig_bases__
|
| 244 |
+
|
| 245 |
+
def test_attr():
|
| 246 |
+
import attr
|
| 247 |
+
@attr.s
|
| 248 |
+
class A:
|
| 249 |
+
a = attr.ib()
|
| 250 |
+
|
| 251 |
+
v = A(1)
|
| 252 |
+
assert dill.copy(v) == v
|
| 253 |
+
|
| 254 |
+
def test_metaclass():
|
| 255 |
+
class metaclass_with_new(type):
|
| 256 |
+
def __new__(mcls, name, bases, ns, **kwds):
|
| 257 |
+
cls = super().__new__(mcls, name, bases, ns, **kwds)
|
| 258 |
+
assert mcls is not None
|
| 259 |
+
assert cls.method(mcls)
|
| 260 |
+
return cls
|
| 261 |
+
def method(cls, mcls):
|
| 262 |
+
return isinstance(cls, mcls)
|
| 263 |
+
|
| 264 |
+
l = locals()
|
| 265 |
+
exec("""class subclass_with_new(metaclass=metaclass_with_new):
|
| 266 |
+
def __new__(cls):
|
| 267 |
+
self = super().__new__(cls)
|
| 268 |
+
return self""", None, l)
|
| 269 |
+
subclass_with_new = l['subclass_with_new']
|
| 270 |
+
|
| 271 |
+
assert dill.copy(subclass_with_new())
|
| 272 |
+
|
| 273 |
+
def test_enummeta():
|
| 274 |
+
from http import HTTPStatus
|
| 275 |
+
import enum
|
| 276 |
+
assert dill.copy(HTTPStatus.OK) is HTTPStatus.OK
|
| 277 |
+
assert dill.copy(enum.EnumMeta) is enum.EnumMeta
|
| 278 |
+
|
| 279 |
+
def test_inherit(): #NOTE: see issue #612
|
| 280 |
+
class Foo:
|
| 281 |
+
w = 0
|
| 282 |
+
x = 1
|
| 283 |
+
y = 1.1
|
| 284 |
+
a = ()
|
| 285 |
+
b = (1,)
|
| 286 |
+
n = None
|
| 287 |
+
|
| 288 |
+
class Bar(Foo):
|
| 289 |
+
w = 2
|
| 290 |
+
x = 1
|
| 291 |
+
y = 1.1
|
| 292 |
+
z = 0.2
|
| 293 |
+
a = ()
|
| 294 |
+
b = (1,)
|
| 295 |
+
c = (2,)
|
| 296 |
+
n = None
|
| 297 |
+
|
| 298 |
+
Baz = dill.copy(Bar)
|
| 299 |
+
|
| 300 |
+
import platform
|
| 301 |
+
is_pypy = platform.python_implementation() == 'PyPy'
|
| 302 |
+
assert Bar.__dict__ == Baz.__dict__
|
| 303 |
+
# ints
|
| 304 |
+
assert 'w' in Bar.__dict__ and 'w' in Baz.__dict__
|
| 305 |
+
assert Bar.__dict__['w'] is Baz.__dict__['w']
|
| 306 |
+
assert 'x' in Bar.__dict__ and 'x' in Baz.__dict__
|
| 307 |
+
assert Bar.__dict__['x'] is Baz.__dict__['x']
|
| 308 |
+
# floats
|
| 309 |
+
assert 'y' in Bar.__dict__ and 'y' in Baz.__dict__
|
| 310 |
+
same = Bar.__dict__['y'] is Baz.__dict__['y']
|
| 311 |
+
assert same if is_pypy else not same
|
| 312 |
+
assert 'z' in Bar.__dict__ and 'z' in Baz.__dict__
|
| 313 |
+
same = Bar.__dict__['z'] is Baz.__dict__['z']
|
| 314 |
+
assert same if is_pypy else not same
|
| 315 |
+
# tuples
|
| 316 |
+
assert 'a' in Bar.__dict__ and 'a' in Baz.__dict__
|
| 317 |
+
assert Bar.__dict__['a'] is Baz.__dict__['a']
|
| 318 |
+
assert 'b' in Bar.__dict__ and 'b' in Baz.__dict__
|
| 319 |
+
assert Bar.__dict__['b'] is not Baz.__dict__['b']
|
| 320 |
+
assert 'c' in Bar.__dict__ and 'c' in Baz.__dict__
|
| 321 |
+
assert Bar.__dict__['c'] is not Baz.__dict__['c']
|
| 322 |
+
# None
|
| 323 |
+
assert 'n' in Bar.__dict__ and 'n' in Baz.__dict__
|
| 324 |
+
assert Bar.__dict__['n'] is Baz.__dict__['n']
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
if __name__ == '__main__':
|
| 328 |
+
test_class_instances()
|
| 329 |
+
test_class_objects()
|
| 330 |
+
test_specialtypes()
|
| 331 |
+
test_namedtuple()
|
| 332 |
+
test_dtype()
|
| 333 |
+
test_array_nested()
|
| 334 |
+
test_array_subclass()
|
| 335 |
+
test_method_decorator()
|
| 336 |
+
test_slots()
|
| 337 |
+
test_origbases()
|
| 338 |
+
test_metaclass()
|
| 339 |
+
test_enummeta()
|
| 340 |
+
test_inherit()
|
lib/python3.12/site-packages/dill/tests/test_extendpickle.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
| 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 |
+
|
| 9 |
+
import dill as pickle
|
| 10 |
+
from io import BytesIO as StringIO
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def my_fn(x):
|
| 14 |
+
return x * 17
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def test_extend():
|
| 18 |
+
obj = lambda : my_fn(34)
|
| 19 |
+
assert obj() == 578
|
| 20 |
+
|
| 21 |
+
obj_io = StringIO()
|
| 22 |
+
pickler = pickle.Pickler(obj_io)
|
| 23 |
+
pickler.dump(obj)
|
| 24 |
+
|
| 25 |
+
obj_str = obj_io.getvalue()
|
| 26 |
+
|
| 27 |
+
obj2_io = StringIO(obj_str)
|
| 28 |
+
unpickler = pickle.Unpickler(obj2_io)
|
| 29 |
+
obj2 = unpickler.load()
|
| 30 |
+
|
| 31 |
+
assert obj2() == 578
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def test_isdill():
|
| 35 |
+
obj_io = StringIO()
|
| 36 |
+
pickler = pickle.Pickler(obj_io)
|
| 37 |
+
assert pickle._dill.is_dill(pickler) is True
|
| 38 |
+
|
| 39 |
+
pickler = pickle._dill.StockPickler(obj_io)
|
| 40 |
+
assert pickle._dill.is_dill(pickler) is False
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
import multiprocess as mp
|
| 44 |
+
pickler = mp.reduction.ForkingPickler(obj_io)
|
| 45 |
+
assert pickle._dill.is_dill(pickler, child=True) is True
|
| 46 |
+
assert pickle._dill.is_dill(pickler, child=False) is False
|
| 47 |
+
except Exception:
|
| 48 |
+
pass
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if __name__ == '__main__':
|
| 52 |
+
test_extend()
|
| 53 |
+
test_isdill()
|
lib/python3.12/site-packages/dill/tests/test_logger.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
|
| 3 |
+
# Author: Leonardo Gama (@leogama)
|
| 4 |
+
# Copyright (c) 2022-2024 The Uncertainty Quantification Foundation.
|
| 5 |
+
# License: 3-clause BSD. The full license text is available at:
|
| 6 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
| 7 |
+
|
| 8 |
+
import logging
|
| 9 |
+
import re
|
| 10 |
+
import tempfile
|
| 11 |
+
|
| 12 |
+
import dill
|
| 13 |
+
from dill import detect
|
| 14 |
+
from dill.logger import stderr_handler, adapter as logger
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
from StringIO import StringIO
|
| 18 |
+
except ImportError:
|
| 19 |
+
from io import StringIO
|
| 20 |
+
|
| 21 |
+
test_obj = {'a': (1, 2), 'b': object(), 'f': lambda x: x**2, 'big': list(range(10))}
|
| 22 |
+
|
| 23 |
+
def test_logging(should_trace):
|
| 24 |
+
buffer = StringIO()
|
| 25 |
+
handler = logging.StreamHandler(buffer)
|
| 26 |
+
logger.addHandler(handler)
|
| 27 |
+
try:
|
| 28 |
+
dill.dumps(test_obj)
|
| 29 |
+
if should_trace:
|
| 30 |
+
regex = re.compile(r'(\S*┬ \w.*[^)]' # begin pickling object
|
| 31 |
+
r'|│*└ # \w.* \[\d+ (\wi)?B])' # object written (with size)
|
| 32 |
+
)
|
| 33 |
+
for line in buffer.getvalue().splitlines():
|
| 34 |
+
assert regex.fullmatch(line)
|
| 35 |
+
return buffer.getvalue()
|
| 36 |
+
else:
|
| 37 |
+
assert buffer.getvalue() == ""
|
| 38 |
+
finally:
|
| 39 |
+
logger.removeHandler(handler)
|
| 40 |
+
buffer.close()
|
| 41 |
+
|
| 42 |
+
def test_trace_to_file(stream_trace):
|
| 43 |
+
file = tempfile.NamedTemporaryFile(mode='r')
|
| 44 |
+
with detect.trace(file.name, mode='w'):
|
| 45 |
+
dill.dumps(test_obj)
|
| 46 |
+
file_trace = file.read()
|
| 47 |
+
file.close()
|
| 48 |
+
# Apparently, objects can change location in memory...
|
| 49 |
+
reghex = re.compile(r'0x[0-9A-Za-z]+')
|
| 50 |
+
file_trace, stream_trace = reghex.sub('0x', file_trace), reghex.sub('0x', stream_trace)
|
| 51 |
+
# PyPy prints dictionary contents with repr(dict)...
|
| 52 |
+
regdict = re.compile(r'(dict\.__repr__ of ).*')
|
| 53 |
+
file_trace, stream_trace = regdict.sub(r'\1{}>', file_trace), regdict.sub(r'\1{}>', stream_trace)
|
| 54 |
+
assert file_trace == stream_trace
|
| 55 |
+
|
| 56 |
+
if __name__ == '__main__':
|
| 57 |
+
logger.removeHandler(stderr_handler)
|
| 58 |
+
test_logging(should_trace=False)
|
| 59 |
+
detect.trace(True)
|
| 60 |
+
test_logging(should_trace=True)
|
| 61 |
+
detect.trace(False)
|
| 62 |
+
test_logging(should_trace=False)
|
| 63 |
+
|
| 64 |
+
loglevel = logging.ERROR
|
| 65 |
+
logger.setLevel(loglevel)
|
| 66 |
+
with detect.trace():
|
| 67 |
+
stream_trace = test_logging(should_trace=True)
|
| 68 |
+
test_logging(should_trace=False)
|
| 69 |
+
assert logger.getEffectiveLevel() == loglevel
|
| 70 |
+
test_trace_to_file(stream_trace)
|
lib/python3.12/site-packages/dill/tests/test_nested.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
| 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 |
+
"""
|
| 9 |
+
test dill's ability to handle nested functions
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import os
|
| 13 |
+
import math
|
| 14 |
+
|
| 15 |
+
import dill as pickle
|
| 16 |
+
pickle.settings['recurse'] = True
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# the nested function: pickle should fail here, but dill is ok.
|
| 20 |
+
def adder(augend):
|
| 21 |
+
zero = [0]
|
| 22 |
+
|
| 23 |
+
def inner(addend):
|
| 24 |
+
return addend + augend + zero[0]
|
| 25 |
+
return inner
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# rewrite the nested function using a class: standard pickle should work here.
|
| 29 |
+
class cadder(object):
|
| 30 |
+
def __init__(self, augend):
|
| 31 |
+
self.augend = augend
|
| 32 |
+
self.zero = [0]
|
| 33 |
+
|
| 34 |
+
def __call__(self, addend):
|
| 35 |
+
return addend + self.augend + self.zero[0]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# rewrite again, but as an old-style class
|
| 39 |
+
class c2adder:
|
| 40 |
+
def __init__(self, augend):
|
| 41 |
+
self.augend = augend
|
| 42 |
+
self.zero = [0]
|
| 43 |
+
|
| 44 |
+
def __call__(self, addend):
|
| 45 |
+
return addend + self.augend + self.zero[0]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# some basic class stuff
|
| 49 |
+
class basic(object):
|
| 50 |
+
pass
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class basic2:
|
| 54 |
+
pass
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
x = 5
|
| 58 |
+
y = 1
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def test_basic():
|
| 62 |
+
a = [0, 1, 2]
|
| 63 |
+
pa = pickle.dumps(a)
|
| 64 |
+
pmath = pickle.dumps(math) #XXX: FAILS in pickle
|
| 65 |
+
pmap = pickle.dumps(map)
|
| 66 |
+
# ...
|
| 67 |
+
la = pickle.loads(pa)
|
| 68 |
+
lmath = pickle.loads(pmath)
|
| 69 |
+
lmap = pickle.loads(pmap)
|
| 70 |
+
assert list(map(math.sin, a)) == list(lmap(lmath.sin, la))
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_basic_class():
|
| 74 |
+
pbasic2 = pickle.dumps(basic2)
|
| 75 |
+
_pbasic2 = pickle.loads(pbasic2)()
|
| 76 |
+
pbasic = pickle.dumps(basic)
|
| 77 |
+
_pbasic = pickle.loads(pbasic)()
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def test_c2adder():
|
| 81 |
+
pc2adder = pickle.dumps(c2adder)
|
| 82 |
+
pc2add5 = pickle.loads(pc2adder)(x)
|
| 83 |
+
assert pc2add5(y) == x+y
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def test_pickled_cadder():
|
| 87 |
+
pcadder = pickle.dumps(cadder)
|
| 88 |
+
pcadd5 = pickle.loads(pcadder)(x)
|
| 89 |
+
assert pcadd5(y) == x+y
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def test_raw_adder_and_inner():
|
| 93 |
+
add5 = adder(x)
|
| 94 |
+
assert add5(y) == x+y
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def test_pickled_adder():
|
| 98 |
+
padder = pickle.dumps(adder)
|
| 99 |
+
padd5 = pickle.loads(padder)(x)
|
| 100 |
+
assert padd5(y) == x+y
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def test_pickled_inner():
|
| 104 |
+
add5 = adder(x)
|
| 105 |
+
pinner = pickle.dumps(add5) #XXX: FAILS in pickle
|
| 106 |
+
p5add = pickle.loads(pinner)
|
| 107 |
+
assert p5add(y) == x+y
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def test_moduledict_where_not_main():
|
| 111 |
+
try:
|
| 112 |
+
from . import test_moduledict
|
| 113 |
+
except ImportError:
|
| 114 |
+
import test_moduledict
|
| 115 |
+
name = 'test_moduledict.py'
|
| 116 |
+
if os.path.exists(name) and os.path.exists(name+'c'):
|
| 117 |
+
os.remove(name+'c')
|
| 118 |
+
|
| 119 |
+
if os.path.exists(name) and hasattr(test_moduledict, "__cached__") \
|
| 120 |
+
and os.path.exists(test_moduledict.__cached__):
|
| 121 |
+
os.remove(getattr(test_moduledict, "__cached__"))
|
| 122 |
+
|
| 123 |
+
if os.path.exists("__pycache__") and not os.listdir("__pycache__"):
|
| 124 |
+
os.removedirs("__pycache__")
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
if __name__ == '__main__':
|
| 128 |
+
test_basic()
|
| 129 |
+
test_basic_class()
|
| 130 |
+
test_c2adder()
|
| 131 |
+
test_pickled_cadder()
|
| 132 |
+
test_raw_adder_and_inner()
|
| 133 |
+
test_pickled_adder()
|
| 134 |
+
test_pickled_inner()
|
| 135 |
+
test_moduledict_where_not_main()
|
lib/python3.12/site-packages/dill/tests/test_restricted.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 9 |
+
import dill
|
| 10 |
+
|
| 11 |
+
class RestrictedType:
|
| 12 |
+
def __bool__(*args, **kwargs):
|
| 13 |
+
raise Exception('Restricted function')
|
| 14 |
+
|
| 15 |
+
__eq__ = __lt__ = __le__ = __ne__ = __gt__ = __ge__ = __hash__ = __bool__
|
| 16 |
+
|
| 17 |
+
glob_obj = RestrictedType()
|
| 18 |
+
|
| 19 |
+
def restricted_func():
|
| 20 |
+
a = glob_obj
|
| 21 |
+
|
| 22 |
+
def test_function_with_restricted_object():
|
| 23 |
+
deserialized = dill.loads(dill.dumps(restricted_func, recurse=True))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
if __name__ == '__main__':
|
| 27 |
+
test_function_with_restricted_object()
|
lib/python3.12/site-packages/dill/tests/test_source.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
| 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 |
+
|
| 9 |
+
from dill.source import getsource, getname, _wrap, likely_import
|
| 10 |
+
from dill.source import getimportable
|
| 11 |
+
from dill._dill import IS_PYPY
|
| 12 |
+
|
| 13 |
+
import sys
|
| 14 |
+
PY310b = 0x30a00b1
|
| 15 |
+
|
| 16 |
+
f = lambda x: x**2
|
| 17 |
+
def g(x): return f(x) - x
|
| 18 |
+
|
| 19 |
+
def h(x):
|
| 20 |
+
def g(x): return x
|
| 21 |
+
return g(x) - x
|
| 22 |
+
|
| 23 |
+
class Foo(object):
|
| 24 |
+
def bar(self, x):
|
| 25 |
+
return x*x+x
|
| 26 |
+
_foo = Foo()
|
| 27 |
+
|
| 28 |
+
def add(x,y):
|
| 29 |
+
return x+y
|
| 30 |
+
|
| 31 |
+
# yes, same as 'f', but things are tricky when it comes to pointers
|
| 32 |
+
squared = lambda x:x**2
|
| 33 |
+
|
| 34 |
+
class Bar:
|
| 35 |
+
pass
|
| 36 |
+
_bar = Bar()
|
| 37 |
+
|
| 38 |
+
# inspect.getsourcelines # dill.source.getblocks
|
| 39 |
+
def test_getsource():
|
| 40 |
+
assert getsource(f) == 'f = lambda x: x**2\n'
|
| 41 |
+
assert getsource(g) == 'def g(x): return f(x) - x\n'
|
| 42 |
+
assert getsource(h) == 'def h(x):\n def g(x): return x\n return g(x) - x\n'
|
| 43 |
+
assert getname(f) == 'f'
|
| 44 |
+
assert getname(g) == 'g'
|
| 45 |
+
assert getname(h) == 'h'
|
| 46 |
+
assert _wrap(f)(4) == 16
|
| 47 |
+
assert _wrap(g)(4) == 12
|
| 48 |
+
assert _wrap(h)(4) == 0
|
| 49 |
+
|
| 50 |
+
assert getname(Foo) == 'Foo'
|
| 51 |
+
assert getname(Bar) == 'Bar'
|
| 52 |
+
assert getsource(Bar) == 'class Bar:\n pass\n'
|
| 53 |
+
assert getsource(Foo) == 'class Foo(object):\n def bar(self, x):\n return x*x+x\n'
|
| 54 |
+
#XXX: add getsource for _foo, _bar
|
| 55 |
+
|
| 56 |
+
# test itself
|
| 57 |
+
def test_itself():
|
| 58 |
+
assert likely_import(likely_import)=='from dill.source import likely_import\n'
|
| 59 |
+
|
| 60 |
+
# builtin functions and objects
|
| 61 |
+
def test_builtin():
|
| 62 |
+
assert likely_import(pow) == 'pow\n'
|
| 63 |
+
assert likely_import(100) == '100\n'
|
| 64 |
+
assert likely_import(True) == 'True\n'
|
| 65 |
+
assert likely_import(pow, explicit=True) == 'from builtins import pow\n'
|
| 66 |
+
assert likely_import(100, explicit=True) == '100\n'
|
| 67 |
+
assert likely_import(True, explicit=True) == 'True\n'
|
| 68 |
+
# this is kinda BS... you can't import a None
|
| 69 |
+
assert likely_import(None) == 'None\n'
|
| 70 |
+
assert likely_import(None, explicit=True) == 'None\n'
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
# other imported functions
|
| 74 |
+
def test_imported():
|
| 75 |
+
from math import sin
|
| 76 |
+
assert likely_import(sin) == 'from math import sin\n'
|
| 77 |
+
|
| 78 |
+
# interactively defined functions
|
| 79 |
+
def test_dynamic():
|
| 80 |
+
assert likely_import(add) == 'from %s import add\n' % __name__
|
| 81 |
+
# interactive lambdas
|
| 82 |
+
assert likely_import(squared) == 'from %s import squared\n' % __name__
|
| 83 |
+
|
| 84 |
+
# classes and class instances
|
| 85 |
+
def test_classes():
|
| 86 |
+
from io import BytesIO as StringIO
|
| 87 |
+
y = "from _io import BytesIO\n"
|
| 88 |
+
x = y if (IS_PYPY or sys.hexversion >= PY310b) else "from io import BytesIO\n"
|
| 89 |
+
s = StringIO()
|
| 90 |
+
|
| 91 |
+
assert likely_import(StringIO) == x
|
| 92 |
+
assert likely_import(s) == y
|
| 93 |
+
# interactively defined classes and class instances
|
| 94 |
+
assert likely_import(Foo) == 'from %s import Foo\n' % __name__
|
| 95 |
+
assert likely_import(_foo) == 'from %s import Foo\n' % __name__
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# test getimportable
|
| 99 |
+
def test_importable():
|
| 100 |
+
assert getimportable(add) == 'from %s import add\n' % __name__
|
| 101 |
+
assert getimportable(squared) == 'from %s import squared\n' % __name__
|
| 102 |
+
assert getimportable(Foo) == 'from %s import Foo\n' % __name__
|
| 103 |
+
assert getimportable(Foo.bar) == 'from %s import bar\n' % __name__
|
| 104 |
+
assert getimportable(_foo.bar) == 'from %s import bar\n' % __name__
|
| 105 |
+
assert getimportable(None) == 'None\n'
|
| 106 |
+
assert getimportable(100) == '100\n'
|
| 107 |
+
|
| 108 |
+
assert getimportable(add, byname=False) == 'def add(x,y):\n return x+y\n'
|
| 109 |
+
assert getimportable(squared, byname=False) == 'squared = lambda x:x**2\n'
|
| 110 |
+
assert getimportable(None, byname=False) == 'None\n'
|
| 111 |
+
assert getimportable(Bar, byname=False) == 'class Bar:\n pass\n'
|
| 112 |
+
assert getimportable(Foo, byname=False) == 'class Foo(object):\n def bar(self, x):\n return x*x+x\n'
|
| 113 |
+
assert getimportable(Foo.bar, byname=False) == 'def bar(self, x):\n return x*x+x\n'
|
| 114 |
+
assert getimportable(Foo.bar, byname=True) == 'from %s import bar\n' % __name__
|
| 115 |
+
assert getimportable(Foo.bar, alias='memo', byname=True) == 'from %s import bar as memo\n' % __name__
|
| 116 |
+
assert getimportable(Foo, alias='memo', byname=True) == 'from %s import Foo as memo\n' % __name__
|
| 117 |
+
assert getimportable(squared, alias='memo', byname=True) == 'from %s import squared as memo\n' % __name__
|
| 118 |
+
assert getimportable(squared, alias='memo', byname=False) == 'memo = squared = lambda x:x**2\n'
|
| 119 |
+
assert getimportable(add, alias='memo', byname=False) == 'def add(x,y):\n return x+y\n\nmemo = add\n'
|
| 120 |
+
assert getimportable(None, alias='memo', byname=False) == 'memo = None\n'
|
| 121 |
+
assert getimportable(100, alias='memo', byname=False) == 'memo = 100\n'
|
| 122 |
+
assert getimportable(add, explicit=True) == 'from %s import add\n' % __name__
|
| 123 |
+
assert getimportable(squared, explicit=True) == 'from %s import squared\n' % __name__
|
| 124 |
+
assert getimportable(Foo, explicit=True) == 'from %s import Foo\n' % __name__
|
| 125 |
+
assert getimportable(Foo.bar, explicit=True) == 'from %s import bar\n' % __name__
|
| 126 |
+
assert getimportable(_foo.bar, explicit=True) == 'from %s import bar\n' % __name__
|
| 127 |
+
assert getimportable(None, explicit=True) == 'None\n'
|
| 128 |
+
assert getimportable(100, explicit=True) == '100\n'
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def test_numpy():
|
| 132 |
+
try:
|
| 133 |
+
from numpy import array
|
| 134 |
+
x = array([1,2,3])
|
| 135 |
+
assert getimportable(x) == 'from numpy import array\narray([1, 2, 3])\n'
|
| 136 |
+
assert getimportable(array) == 'from %s import array\n' % array.__module__
|
| 137 |
+
assert getimportable(x, byname=False) == 'from numpy import array\narray([1, 2, 3])\n'
|
| 138 |
+
assert getimportable(array, byname=False) == 'from %s import array\n' % array.__module__
|
| 139 |
+
except ImportError: pass
|
| 140 |
+
|
| 141 |
+
#NOTE: if before likely_import(pow), will cause pow to throw AssertionError
|
| 142 |
+
def test_foo():
|
| 143 |
+
assert getimportable(_foo, byname=False).startswith("import dill\nclass Foo(object):\n def bar(self, x):\n return x*x+x\ndill.loads(")
|
| 144 |
+
|
| 145 |
+
if __name__ == '__main__':
|
| 146 |
+
test_getsource()
|
| 147 |
+
test_itself()
|
| 148 |
+
test_builtin()
|
| 149 |
+
test_imported()
|
| 150 |
+
test_dynamic()
|
| 151 |
+
test_classes()
|
| 152 |
+
test_importable()
|
| 153 |
+
test_numpy()
|
| 154 |
+
test_foo()
|
lib/python3.12/site-packages/dill/tests/test_weakref.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
| 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 |
+
|
| 9 |
+
import dill
|
| 10 |
+
dill.settings['recurse'] = True
|
| 11 |
+
import weakref
|
| 12 |
+
|
| 13 |
+
class _class:
|
| 14 |
+
def _method(self):
|
| 15 |
+
pass
|
| 16 |
+
|
| 17 |
+
class _callable_class:
|
| 18 |
+
def __call__(self):
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
+
def _function():
|
| 22 |
+
pass
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_weakref():
|
| 26 |
+
o = _class()
|
| 27 |
+
oc = _callable_class()
|
| 28 |
+
f = _function
|
| 29 |
+
x = _class
|
| 30 |
+
|
| 31 |
+
# ReferenceType
|
| 32 |
+
r = weakref.ref(o)
|
| 33 |
+
d_r = weakref.ref(_class())
|
| 34 |
+
fr = weakref.ref(f)
|
| 35 |
+
xr = weakref.ref(x)
|
| 36 |
+
|
| 37 |
+
# ProxyType
|
| 38 |
+
p = weakref.proxy(o)
|
| 39 |
+
d_p = weakref.proxy(_class())
|
| 40 |
+
|
| 41 |
+
# CallableProxyType
|
| 42 |
+
cp = weakref.proxy(oc)
|
| 43 |
+
d_cp = weakref.proxy(_callable_class())
|
| 44 |
+
fp = weakref.proxy(f)
|
| 45 |
+
xp = weakref.proxy(x)
|
| 46 |
+
|
| 47 |
+
objlist = [r,d_r,fr,xr, p,d_p, cp,d_cp,fp,xp]
|
| 48 |
+
#dill.detect.trace(True)
|
| 49 |
+
|
| 50 |
+
for obj in objlist:
|
| 51 |
+
res = dill.detect.errors(obj)
|
| 52 |
+
if res:
|
| 53 |
+
print ("%r:\n %s" % (obj, res))
|
| 54 |
+
# else:
|
| 55 |
+
# print ("PASS: %s" % obj)
|
| 56 |
+
assert not res
|
| 57 |
+
|
| 58 |
+
def test_dictproxy():
|
| 59 |
+
from dill._dill import DictProxyType
|
| 60 |
+
try:
|
| 61 |
+
m = DictProxyType({"foo": "bar"})
|
| 62 |
+
except Exception:
|
| 63 |
+
m = type.__dict__
|
| 64 |
+
mp = dill.copy(m)
|
| 65 |
+
assert mp.items() == m.items()
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
if __name__ == '__main__':
|
| 69 |
+
test_weakref()
|
| 70 |
+
from dill._dill import IS_PYPY
|
| 71 |
+
if not IS_PYPY:
|
| 72 |
+
test_dictproxy()
|