code object reducer.
(obj)
| 825 | |
| 826 | |
| 827 | def _code_reduce(obj): |
| 828 | """code object reducer.""" |
| 829 | # If you are not sure about the order of arguments, take a look at help |
| 830 | # of the specific type from types, for example: |
| 831 | # >>> from types import CodeType |
| 832 | # >>> help(CodeType) |
| 833 | |
| 834 | # Hack to circumvent non-predictable memoization caused by string interning. |
| 835 | # See the inline comment in _class_setstate for details. |
| 836 | co_name = "".join(obj.co_name) |
| 837 | |
| 838 | # Create shallow copies of these tuple to make cloudpickle payload deterministic. |
| 839 | # When creating a code object during load, copies of these four tuples are |
| 840 | # created, while in the main process, these tuples can be shared. |
| 841 | # By always creating copies, we make sure the resulting payload is deterministic. |
| 842 | co_names = tuple(name for name in obj.co_names) |
| 843 | co_varnames = tuple(name for name in obj.co_varnames) |
| 844 | co_freevars = tuple(name for name in obj.co_freevars) |
| 845 | co_cellvars = tuple(name for name in obj.co_cellvars) |
| 846 | if hasattr(obj, "co_exceptiontable"): |
| 847 | # Python 3.11 and later: there are some new attributes |
| 848 | # related to the enhanced exceptions. |
| 849 | args = ( |
| 850 | obj.co_argcount, |
| 851 | obj.co_posonlyargcount, |
| 852 | obj.co_kwonlyargcount, |
| 853 | obj.co_nlocals, |
| 854 | obj.co_stacksize, |
| 855 | obj.co_flags, |
| 856 | obj.co_code, |
| 857 | obj.co_consts, |
| 858 | co_names, |
| 859 | co_varnames, |
| 860 | obj.co_filename, |
| 861 | co_name, |
| 862 | obj.co_qualname, |
| 863 | obj.co_firstlineno, |
| 864 | obj.co_linetable, |
| 865 | obj.co_exceptiontable, |
| 866 | co_freevars, |
| 867 | co_cellvars, |
| 868 | ) |
| 869 | elif hasattr(obj, "co_linetable"): |
| 870 | # Python 3.10 and later: obj.co_lnotab is deprecated and constructor |
| 871 | # expects obj.co_linetable instead. |
| 872 | args = ( |
| 873 | obj.co_argcount, |
| 874 | obj.co_posonlyargcount, |
| 875 | obj.co_kwonlyargcount, |
| 876 | obj.co_nlocals, |
| 877 | obj.co_stacksize, |
| 878 | obj.co_flags, |
| 879 | obj.co_code, |
| 880 | obj.co_consts, |
| 881 | co_names, |
| 882 | co_varnames, |
| 883 | obj.co_filename, |
| 884 | co_name, |
nothing calls this directly
no test coverage detected
searching dependent graphs…