From a6075bf01420a362c6d1a44ddebdc272eae8d4a8 Mon Sep 17 00:00:00 2001 From: zheng-guannan577 <2114188592@qq.com> Date: Fri, 13 Nov 2026 09:52:07 +0800 Subject: [PATCH 1/2] test: cover is_tornado_coroutine False branches Add tests for is_tornado_coroutine with and without tornado.gen --- tests/cloudpickle_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py index e2097d1c..dcab5878 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -3180,5 +3180,23 @@ def test_module_level_pickler(): assert cloudpickle.Pickler is cloudpickle.CloudPickler +def test_is_tornado_coroutine_without_tornado_gen(monkeypatch): + # is_tornado_coroutine returns False when tornado.gen was never + # imported. See https://github.com/cloudpipe/cloudpickle/issues/346 + monkeypatch.delitem(sys.modules, "tornado.gen", raising=False) + with pytest.warns(DeprecationWarning, match="deprecated"): + assert cloudpickle.is_tornado_coroutine(lambda: None) is False + + +def test_is_tornado_coroutine_with_old_tornado(monkeypatch): + # Simulate a Tornado version too old to provide + # tornado.gen.is_coroutine_function. + # See https://github.com/cloudpipe/cloudpickle/issues/346 + stub_gen = types.ModuleType("tornado.gen") + monkeypatch.setitem(sys.modules, "tornado.gen", stub_gen) + with pytest.warns(DeprecationWarning, match="deprecated"): + assert cloudpickle.is_tornado_coroutine(lambda: None) is False + + if __name__ == "__main__": unittest.main() From 706ed466c7ce7d204eb63f49ab47d730ea5cfbcc Mon Sep 17 00:00:00 2001 From: zheng-guannan577 <2114188592@qq.com> Date: Fri, 13 Nov 2026 09:54:22 +0800 Subject: [PATCH 2/2] test: cover cloudpickle_fast shim forwarding --- tests/test_backward_compat.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_backward_compat.py b/tests/test_backward_compat.py index 1d1d70a9..dbe12c7f 100644 --- a/tests/test_backward_compat.py +++ b/tests/test_backward_compat.py @@ -13,6 +13,7 @@ import pickle import pytest +import cloudpickle from .generate_old_pickles import PICKLE_DIRECTORY @@ -93,3 +94,25 @@ def test_complex_function(): def test_nested_function(): f = load_obj("nested_function.pkl") assert f(41) == 42 + + +def test_cloudpickle_fast_forwards_public_names(): + # cloudpickle_fast is a compatibility shim for pickles generated by + # previous cloudpickle versions: attribute access is forwarded to + # cloudpickle.cloudpickle through __getattr__ (PEP 562). + # See https://github.com/cloudpipe/cloudpickle/issues/346 + from cloudpickle import cloudpickle_fast + + assert cloudpickle_fast.CloudPickler is cloudpickle.CloudPickler + assert cloudpickle_fast.Pickler is cloudpickle.Pickler + assert cloudpickle_fast.dumps is cloudpickle.dumps + assert cloudpickle_fast.loads is cloudpickle.loads + + +def test_cloudpickle_fast_unknown_attribute_raises_attribute_error(): + from cloudpickle import cloudpickle_fast + + with pytest.raises(AttributeError): + # Accessing a missing attribute is the point: it exercises + # cloudpickle_fast.__getattr__. + cloudpickle_fast.this_attribute_does_not_exist # noqa: B018