diff --git a/.github/workflows/generate-pickle-files.yml b/.github/workflows/generate-pickle-files.yml new file mode 100644 index 000000000..1763d3531 --- /dev/null +++ b/.github/workflows/generate-pickle-files.yml @@ -0,0 +1,46 @@ +name: Generate static pickle files + +on: pull_request + +jobs: + build: + strategy: + matrix: + python_version: [3.6, 3.7, 3.8, 3.9, "pypy3"] + cloudpickle_version: [1.5.0] + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python_version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python_version }} + + - name: Install project and dependencies + shell: bash + run: python -m pip install cloudpickle==${{ matrix.cloudpickle_version }} + + - name: Display Python version + shell: bash + run: python -c "import sys; print(sys.version)" + + - name: List software environment + shell: bash + run: python -m pip list + + - name: Generate pickle files + shell: bash + run: | + cd tests + rm -rf old_pickles + python generate_old_pickles.py + cd ../ + + - name: Upload pickle files + uses: actions/upload-artifact@v2 + with: + name: old_pickles + path: tests/old_pickles \ No newline at end of file diff --git a/cloudpickle/cloudpickle.py b/cloudpickle/cloudpickle.py index 347b38695..287cb3b13 100644 --- a/cloudpickle/cloudpickle.py +++ b/cloudpickle/cloudpickle.py @@ -645,23 +645,13 @@ def parametrized_type_hint_getinitargs(obj): return initargs -# Tornado support - -def is_tornado_coroutine(func): - """ - Return whether *func* is a Tornado coroutine function. - Running coroutines are not supported. - """ - if 'tornado.gen' not in sys.modules: - return False - gen = sys.modules['tornado.gen'] - if not hasattr(gen, "is_coroutine_function"): - # Tornado version is too old - return False - return gen.is_coroutine_function(func) - - def _rebuild_tornado_coroutine(func): + # This function is deprecated and should be removed in cloudpickle 2.1 + warnings.warn( + "A pickle file created using an old version of cloudpickle " + "is currently being loaded. This is no longer supported by cloudpickle and " + "will be removed in cloudpickle 2.1", category=FutureWarning + ) from tornado import gen return gen.coroutine(func) @@ -688,10 +678,22 @@ def dynamic_subimport(name, vars): def _gen_ellipsis(): + # this function is deprecated and should be removed in cloudpickle 2.1 + warnings.warn( + "a pickle file created using an old version of cloudpickle " + "is currently being loaded. this is no longer supported by cloudpickle and " + "will be removed in cloudpickle 2.1", category=FutureWarning + ) return Ellipsis def _gen_not_implemented(): + # This function is deprecated and should be removed in cloudpickle 2.1 + warnings.warn( + "A pickle file created using an old version of cloudpickle " + "is currently being loaded. This is no longer supported by cloudpickle and " + "will be removed in cloudpickle 2.1", category=FutureWarning + ) return NotImplemented @@ -729,10 +731,7 @@ def __reduce__(cls): def _fill_function(*args): - """Fills in the rest of function data into the skeleton function object - - The skeleton itself is create by _make_skel_func(). - """ + """Fills in the rest of function data into the skeleton function object""" if len(args) == 2: func = args[0] state = args[1] @@ -809,33 +808,6 @@ def _make_cell(value=_empty_cell_value): return cell -def _make_skel_func(code, cell_count, base_globals=None): - """ Creates a skeleton function object that contains just the provided - code and the correct number of cells in func_closure. All other - func attributes (e.g. func_globals) are empty. - """ - # This function is deprecated and should be removed in cloudpickle 1.7 - warnings.warn( - "A pickle file created using an old (<=1.4.1) version of cloudpickle " - "is currently being loaded. This is not supported by cloudpickle and " - "will break in cloudpickle 1.7", category=UserWarning - ) - # This is backward-compatibility code: for cloudpickle versions between - # 0.5.4 and 0.7, base_globals could be a string or None. base_globals - # should now always be a dictionary. - if base_globals is None or isinstance(base_globals, str): - base_globals = {} - - base_globals['__builtins__'] = __builtins__ - - closure = ( - tuple(_make_empty_cell() for _ in range(cell_count)) - if cell_count >= 0 else - None - ) - return types.FunctionType(code, base_globals, None, None, closure) - - def _make_skeleton_class(type_constructor, name, bases, type_kwargs, class_tracker_id, extra): """Build dynamic class with an empty __dict__ to be filled once memoized diff --git a/tests/old_pickles/cpython_35/class_with_type_hints.pkl b/tests/old_pickles/cpython_35/class_with_type_hints.pkl deleted file mode 100644 index 6885eca4b..000000000 Binary files a/tests/old_pickles/cpython_35/class_with_type_hints.pkl and /dev/null differ diff --git a/tests/old_pickles/cpython_35/function_with_type_hints.pkl b/tests/old_pickles/cpython_35/function_with_type_hints.pkl deleted file mode 100644 index 554f24686..000000000 Binary files a/tests/old_pickles/cpython_35/function_with_type_hints.pkl and /dev/null differ diff --git a/tests/old_pickles/cpython_35/nested_function.pkl b/tests/old_pickles/cpython_35/nested_function.pkl deleted file mode 100644 index a71d0e425..000000000 Binary files a/tests/old_pickles/cpython_35/nested_function.pkl and /dev/null differ diff --git a/tests/old_pickles/cpython_35/simple_class.pkl b/tests/old_pickles/cpython_35/simple_class.pkl deleted file mode 100644 index 8d3366da1..000000000 Binary files a/tests/old_pickles/cpython_35/simple_class.pkl and /dev/null differ diff --git a/tests/old_pickles/cpython_35/simple_enum.pkl b/tests/old_pickles/cpython_35/simple_enum.pkl deleted file mode 100644 index ce7b35c4c..000000000 Binary files a/tests/old_pickles/cpython_35/simple_enum.pkl and /dev/null differ diff --git a/tests/old_pickles/cpython_35/simple_func.pkl b/tests/old_pickles/cpython_35/simple_func.pkl deleted file mode 100644 index ee6525bb3..000000000 Binary files a/tests/old_pickles/cpython_35/simple_func.pkl and /dev/null differ diff --git a/tests/old_pickles/cpython_35/simple_module.pkl b/tests/old_pickles/cpython_35/simple_module.pkl deleted file mode 100644 index ddbbcb02e..000000000 Binary files a/tests/old_pickles/cpython_35/simple_module.pkl and /dev/null differ diff --git a/tests/old_pickles/cpython_36/class_with_type_hints.pkl b/tests/old_pickles/cpython_36/class_with_type_hints.pkl index deea20ff7..f69ba6dbc 100644 Binary files a/tests/old_pickles/cpython_36/class_with_type_hints.pkl and b/tests/old_pickles/cpython_36/class_with_type_hints.pkl differ diff --git a/tests/old_pickles/cpython_36/function_with_type_hints.pkl b/tests/old_pickles/cpython_36/function_with_type_hints.pkl index 69fe362b9..8c10e0e8e 100644 Binary files a/tests/old_pickles/cpython_36/function_with_type_hints.pkl and b/tests/old_pickles/cpython_36/function_with_type_hints.pkl differ diff --git a/tests/old_pickles/cpython_36/nested_function.pkl b/tests/old_pickles/cpython_36/nested_function.pkl index 0731174f2..410cbc4f4 100644 Binary files a/tests/old_pickles/cpython_36/nested_function.pkl and b/tests/old_pickles/cpython_36/nested_function.pkl differ diff --git a/tests/old_pickles/cpython_36/simple_class.pkl b/tests/old_pickles/cpython_36/simple_class.pkl index f41002166..4737435a7 100644 Binary files a/tests/old_pickles/cpython_36/simple_class.pkl and b/tests/old_pickles/cpython_36/simple_class.pkl differ diff --git a/tests/old_pickles/cpython_36/simple_enum.pkl b/tests/old_pickles/cpython_36/simple_enum.pkl index 7351bda2a..994b2481c 100644 Binary files a/tests/old_pickles/cpython_36/simple_enum.pkl and b/tests/old_pickles/cpython_36/simple_enum.pkl differ diff --git a/tests/old_pickles/cpython_36/simple_func.pkl b/tests/old_pickles/cpython_36/simple_func.pkl index a6b82cd59..7e7d45729 100644 Binary files a/tests/old_pickles/cpython_36/simple_func.pkl and b/tests/old_pickles/cpython_36/simple_func.pkl differ diff --git a/tests/old_pickles/cpython_36/simple_module.pkl b/tests/old_pickles/cpython_36/simple_module.pkl index 140333553..34e5051d5 100644 Binary files a/tests/old_pickles/cpython_36/simple_module.pkl and b/tests/old_pickles/cpython_36/simple_module.pkl differ diff --git a/tests/old_pickles/cpython_37/class_with_type_hints.pkl b/tests/old_pickles/cpython_37/class_with_type_hints.pkl index 2716dfdd2..bafe505ed 100644 Binary files a/tests/old_pickles/cpython_37/class_with_type_hints.pkl and b/tests/old_pickles/cpython_37/class_with_type_hints.pkl differ diff --git a/tests/old_pickles/cpython_37/function_with_type_hints.pkl b/tests/old_pickles/cpython_37/function_with_type_hints.pkl index 867b18a89..1054d6d6a 100644 Binary files a/tests/old_pickles/cpython_37/function_with_type_hints.pkl and b/tests/old_pickles/cpython_37/function_with_type_hints.pkl differ diff --git a/tests/old_pickles/cpython_37/nested_function.pkl b/tests/old_pickles/cpython_37/nested_function.pkl index 0731174f2..410cbc4f4 100644 Binary files a/tests/old_pickles/cpython_37/nested_function.pkl and b/tests/old_pickles/cpython_37/nested_function.pkl differ diff --git a/tests/old_pickles/cpython_37/simple_class.pkl b/tests/old_pickles/cpython_37/simple_class.pkl index 14902639c..fdf03a509 100644 Binary files a/tests/old_pickles/cpython_37/simple_class.pkl and b/tests/old_pickles/cpython_37/simple_class.pkl differ diff --git a/tests/old_pickles/cpython_37/simple_enum.pkl b/tests/old_pickles/cpython_37/simple_enum.pkl index bfc26fa8f..262203a73 100644 Binary files a/tests/old_pickles/cpython_37/simple_enum.pkl and b/tests/old_pickles/cpython_37/simple_enum.pkl differ diff --git a/tests/old_pickles/cpython_37/simple_func.pkl b/tests/old_pickles/cpython_37/simple_func.pkl index a6b82cd59..7e7d45729 100644 Binary files a/tests/old_pickles/cpython_37/simple_func.pkl and b/tests/old_pickles/cpython_37/simple_func.pkl differ diff --git a/tests/old_pickles/cpython_37/simple_module.pkl b/tests/old_pickles/cpython_37/simple_module.pkl index 140333553..34e5051d5 100644 Binary files a/tests/old_pickles/cpython_37/simple_module.pkl and b/tests/old_pickles/cpython_37/simple_module.pkl differ diff --git a/tests/old_pickles/cpython_38/class_with_type_hints.pkl b/tests/old_pickles/cpython_38/class_with_type_hints.pkl index 5981dce90..9d53c5264 100644 Binary files a/tests/old_pickles/cpython_38/class_with_type_hints.pkl and b/tests/old_pickles/cpython_38/class_with_type_hints.pkl differ diff --git a/tests/old_pickles/cpython_38/function_with_type_hints.pkl b/tests/old_pickles/cpython_38/function_with_type_hints.pkl index 269639184..34a8cf647 100644 Binary files a/tests/old_pickles/cpython_38/function_with_type_hints.pkl and b/tests/old_pickles/cpython_38/function_with_type_hints.pkl differ diff --git a/tests/old_pickles/cpython_38/nested_function.pkl b/tests/old_pickles/cpython_38/nested_function.pkl index e495cd765..c8dbe74e6 100644 Binary files a/tests/old_pickles/cpython_38/nested_function.pkl and b/tests/old_pickles/cpython_38/nested_function.pkl differ diff --git a/tests/old_pickles/cpython_38/simple_class.pkl b/tests/old_pickles/cpython_38/simple_class.pkl index bc22f06d8..778dbc8ea 100644 Binary files a/tests/old_pickles/cpython_38/simple_class.pkl and b/tests/old_pickles/cpython_38/simple_class.pkl differ diff --git a/tests/old_pickles/cpython_38/simple_enum.pkl b/tests/old_pickles/cpython_38/simple_enum.pkl index a6c630455..3152a3f2c 100644 Binary files a/tests/old_pickles/cpython_38/simple_enum.pkl and b/tests/old_pickles/cpython_38/simple_enum.pkl differ diff --git a/tests/old_pickles/cpython_38/simple_func.pkl b/tests/old_pickles/cpython_38/simple_func.pkl index df7c83a5d..a8b843e73 100644 Binary files a/tests/old_pickles/cpython_38/simple_func.pkl and b/tests/old_pickles/cpython_38/simple_func.pkl differ diff --git a/tests/old_pickles/cpython_39/class_with_type_hints.pkl b/tests/old_pickles/cpython_39/class_with_type_hints.pkl new file mode 100644 index 000000000..1238a629e Binary files /dev/null and b/tests/old_pickles/cpython_39/class_with_type_hints.pkl differ diff --git a/tests/old_pickles/cpython_39/function_with_type_hints.pkl b/tests/old_pickles/cpython_39/function_with_type_hints.pkl new file mode 100644 index 000000000..f8c2d0f57 Binary files /dev/null and b/tests/old_pickles/cpython_39/function_with_type_hints.pkl differ diff --git a/tests/old_pickles/cpython_39/nested_function.pkl b/tests/old_pickles/cpython_39/nested_function.pkl new file mode 100644 index 000000000..5ea958731 Binary files /dev/null and b/tests/old_pickles/cpython_39/nested_function.pkl differ diff --git a/tests/old_pickles/cpython_39/simple_class.pkl b/tests/old_pickles/cpython_39/simple_class.pkl new file mode 100644 index 000000000..f12f91b84 Binary files /dev/null and b/tests/old_pickles/cpython_39/simple_class.pkl differ diff --git a/tests/old_pickles/cpython_39/simple_enum.pkl b/tests/old_pickles/cpython_39/simple_enum.pkl new file mode 100644 index 000000000..abd81a34d Binary files /dev/null and b/tests/old_pickles/cpython_39/simple_enum.pkl differ diff --git a/tests/old_pickles/cpython_39/simple_func.pkl b/tests/old_pickles/cpython_39/simple_func.pkl new file mode 100644 index 000000000..aa2ea0b1d Binary files /dev/null and b/tests/old_pickles/cpython_39/simple_func.pkl differ diff --git a/tests/old_pickles/cpython_39/simple_module.pkl b/tests/old_pickles/cpython_39/simple_module.pkl new file mode 100644 index 000000000..a5f850623 Binary files /dev/null and b/tests/old_pickles/cpython_39/simple_module.pkl differ diff --git a/tests/old_pickles/pypy_36/class_with_type_hints.pkl b/tests/old_pickles/pypy_36/class_with_type_hints.pkl index 3bda8c2ae..a498dbc0e 100644 Binary files a/tests/old_pickles/pypy_36/class_with_type_hints.pkl and b/tests/old_pickles/pypy_36/class_with_type_hints.pkl differ diff --git a/tests/old_pickles/pypy_36/function_with_type_hints.pkl b/tests/old_pickles/pypy_36/function_with_type_hints.pkl index d310462a0..d4c64f4c2 100644 Binary files a/tests/old_pickles/pypy_36/function_with_type_hints.pkl and b/tests/old_pickles/pypy_36/function_with_type_hints.pkl differ diff --git a/tests/old_pickles/pypy_36/nested_function.pkl b/tests/old_pickles/pypy_36/nested_function.pkl new file mode 100644 index 000000000..b831f166a Binary files /dev/null and b/tests/old_pickles/pypy_36/nested_function.pkl differ diff --git a/tests/old_pickles/pypy_36/simple_class.pkl b/tests/old_pickles/pypy_36/simple_class.pkl index 202e4f795..1f7362ccd 100644 Binary files a/tests/old_pickles/pypy_36/simple_class.pkl and b/tests/old_pickles/pypy_36/simple_class.pkl differ diff --git a/tests/old_pickles/pypy_36/simple_enum.pkl b/tests/old_pickles/pypy_36/simple_enum.pkl index 64cbbdddc..1c43d6808 100644 Binary files a/tests/old_pickles/pypy_36/simple_enum.pkl and b/tests/old_pickles/pypy_36/simple_enum.pkl differ diff --git a/tests/old_pickles/pypy_36/simple_func.pkl b/tests/old_pickles/pypy_36/simple_func.pkl index 1761a387a..0bb1db5ef 100644 Binary files a/tests/old_pickles/pypy_36/simple_func.pkl and b/tests/old_pickles/pypy_36/simple_func.pkl differ diff --git a/tests/old_pickles/pypy_36/simple_module.pkl b/tests/old_pickles/pypy_36/simple_module.pkl index 140333553..34e5051d5 100644 Binary files a/tests/old_pickles/pypy_36/simple_module.pkl and b/tests/old_pickles/pypy_36/simple_module.pkl differ diff --git a/tests/test_backward_compat.py b/tests/test_backward_compat.py index 20977a74b..624b277a9 100644 --- a/tests/test_backward_compat.py +++ b/tests/test_backward_compat.py @@ -17,11 +17,7 @@ from .generate_old_pickles import PICKLE_DIRECTORY -def load_obj(filename, check_deprecation_warning='auto'): - if check_deprecation_warning == 'auto': - # pickles files generated with cloudpickle_fast.py on old versions of - # coudpickle with Python < 3.8 use non-deprecated reconstructors. - check_deprecation_warning = (sys.version_info < (3, 8)) +def load_obj(filename, check_deprecation_warning=False): pickle_filepath = PICKLE_DIRECTORY / filename if not pickle_filepath.exists(): pytest.skip("Could not find {}".format(str(pickle_filepath))) @@ -61,13 +57,13 @@ def test_dynamic_module(): def test_simple_enum(): - enum = load_obj("simple_enum.pkl", check_deprecation_warning=False) + enum = load_obj("simple_enum.pkl") assert hasattr(enum, "RED") assert enum.RED == 1 assert enum.BLUE == 2 # test enum tracking feature - new_enum = load_obj("simple_enum.pkl", check_deprecation_warning=False) + new_enum = load_obj("simple_enum.pkl") assert new_enum is enum