From 124826bdf38c29a6a9952e8c97204077bdac99e9 Mon Sep 17 00:00:00 2001 From: tommoral Date: Sun, 12 Nov 2023 11:48:30 +0100 Subject: [PATCH] CLN blackify the code --- ci/install_coverage_subprocess_pth.py | 8 ++++---- cloudpickle/cloudpickle_fast.py | 1 + tests/cloudpickle_test.py | 19 ++++++++++++------- .../_cloudpickle_testpkg/__init__.py | 5 ++++- .../_cloudpickle_testpkg/mod.py | 12 ++++-------- tests/cloudpickle_testpkg/setup.py | 16 ++++++++-------- tests/generate_old_pickles.py | 1 + tests/mock_local_folder/mod.py | 1 + tests/test_backward_compat.py | 1 + tests/testutils.py | 4 ++-- 10 files changed, 38 insertions(+), 30 deletions(-) diff --git a/ci/install_coverage_subprocess_pth.py b/ci/install_coverage_subprocess_pth.py index 927820b9..a842ce96 100644 --- a/ci/install_coverage_subprocess_pth.py +++ b/ci/install_coverage_subprocess_pth.py @@ -9,8 +9,8 @@ import coverage; coverage.process_startup() """ -filename = op.join(get_path('purelib'), 'coverage_subprocess.pth') -with open(filename, 'wb') as f: - f.write(FILE_CONTENT.encode('ascii')) +filename = op.join(get_path("purelib"), "coverage_subprocess.pth") +with open(filename, "wb") as f: + f.write(FILE_CONTENT.encode("ascii")) -print('Installed subprocess coverage support: %s' % filename) +print("Installed subprocess coverage support: %s" % filename) diff --git a/cloudpickle/cloudpickle_fast.py b/cloudpickle/cloudpickle_fast.py index 52d6732e..20280f0c 100644 --- a/cloudpickle/cloudpickle_fast.py +++ b/cloudpickle/cloudpickle_fast.py @@ -6,6 +6,7 @@ See: tests/test_backward_compat.py """ + from . import cloudpickle diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py index 1caff739..7995901e 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -1988,8 +1988,10 @@ def test_dynamic_class_determinist_subworker_order(self): # This checks that the order of the class attributes is deterministic. with subprocess_worker(protocol=self.protocol) as w: + class A: - '''Simple class definition''' + """Simple class definition""" + pass A_dump = w.run(cloudpickle.dumps, A) @@ -2000,7 +2002,7 @@ class A: # the class and thus `__doc__` before populating it. class A: name = "A" - __doc__ = '''Updated class definition''' + __doc__ = "Updated class definition" A_dump = w.run(cloudpickle.dumps, A) check_determinist_pickle(A_dump, cloudpickle.dumps(A)) @@ -2008,9 +2010,8 @@ class A: # If the doc is defined in `__init__`, this can cause ordering changes due to the way # we reconstruct the class with _make_class_skeleton. Make sure the order is deterministic class A: - def __init__(self): - '''Class definition with explicit __init__''' + """Class definition with explicit __init__""" pass A_dump = w.run(cloudpickle.dumps, A) @@ -2024,7 +2025,8 @@ def test_dynamic_class_determinist_subworker_str_interning(self): # Due to interning of class attributes, check that this does not create issues # with dynamic function definition. class A: - '''Class with potential string interning issues.''' + """Class with potential string interning issues.""" + arg_1 = "class_value" def join(self): @@ -2038,14 +2040,17 @@ def test_method(self, arg_1, join): # XXX - this does not seem to work, and I am not sure there is an easy fix. class A: - '''Class with potential string interning issues.''' + """Class with potential string interning issues.""" + arg_1 = "join" def join(self, arg_1): pass A_dump = w.run(cloudpickle.dumps, A) - pytest.xfail("This test is expected to fail due to string interning errors.") + pytest.xfail( + "This test is expected to fail due to string interning errors." + ) check_determinist_pickle(A_dump, cloudpickle.dumps(A)) @pytest.mark.skipif( diff --git a/tests/cloudpickle_testpkg/_cloudpickle_testpkg/__init__.py b/tests/cloudpickle_testpkg/_cloudpickle_testpkg/__init__.py index 58eb1867..2051e4c0 100644 --- a/tests/cloudpickle_testpkg/_cloudpickle_testpkg/__init__.py +++ b/tests/cloudpickle_testpkg/_cloudpickle_testpkg/__init__.py @@ -27,19 +27,22 @@ def relative_imports_factory(): Relative import of functions living both inside modules and packages are tested. """ + def f(): # module_function belongs to _cloudpickle_testpkg.mod, which is a # module from .mod import module_function + return module_function() def g(): # package_function belongs to _cloudpickle_testpkg, which is a package from . import package_function + return package_function() return f, g some_singleton = _SingletonClass() -T = typing.TypeVar('T') +T = typing.TypeVar("T") diff --git a/tests/cloudpickle_testpkg/_cloudpickle_testpkg/mod.py b/tests/cloudpickle_testpkg/_cloudpickle_testpkg/mod.py index e8225a4c..f38cdb70 100644 --- a/tests/cloudpickle_testpkg/_cloudpickle_testpkg/mod.py +++ b/tests/cloudpickle_testpkg/_cloudpickle_testpkg/mod.py @@ -20,7 +20,7 @@ # module. The following lines emulate such a behavior without being a compiled # extension module. -submodule_name = '_cloudpickle_testpkg.mod.dynamic_submodule' +submodule_name = "_cloudpickle_testpkg.mod.dynamic_submodule" dynamic_submodule = types.ModuleType(submodule_name) # This line allows the dynamic_module to be imported using either one of: @@ -32,7 +32,7 @@ # so this dynamic module could be binded to another name. This behavior is # demonstrated with `dynamic_submodule_two` -submodule_name_two = '_cloudpickle_testpkg.mod.dynamic_submodule_two' +submodule_name_two = "_cloudpickle_testpkg.mod.dynamic_submodule_two" # Notice the inconsistent name binding, breaking attribute lookup-based import # attempts. another_submodule = types.ModuleType(submodule_name_two) @@ -41,9 +41,7 @@ # In this third case, the module is not added to sys.modules, and can only be # imported using attribute lookup-based imports. -submodule_three = types.ModuleType( - '_cloudpickle_testpkg.mod.dynamic_submodule_three' -) +submodule_three = types.ModuleType("_cloudpickle_testpkg.mod.dynamic_submodule_three") code = """ def f(x): return x @@ -53,9 +51,7 @@ def f(x): # What about a dynamic submodule inside a dynamic submodule inside an # importable module? -subsubmodule_name = ( - '_cloudpickle_testpkg.mod.dynamic_submodule.dynamic_subsubmodule' -) +subsubmodule_name = "_cloudpickle_testpkg.mod.dynamic_submodule.dynamic_subsubmodule" dynamic_subsubmodule = types.ModuleType(subsubmodule_name) dynamic_submodule.dynamic_subsubmodule = dynamic_subsubmodule sys.modules[subsubmodule_name] = dynamic_subsubmodule diff --git a/tests/cloudpickle_testpkg/setup.py b/tests/cloudpickle_testpkg/setup.py index 5cb49f90..403b69f7 100644 --- a/tests/cloudpickle_testpkg/setup.py +++ b/tests/cloudpickle_testpkg/setup.py @@ -5,12 +5,12 @@ setup( - name='cloudpickle_testpkg', - version='0.0.0', - description='Package used only for cloudpickle testing purposes', - author='Cloudpipe', - author_email='cloudpipe@googlegroups.com', - license='BSD 3-Clause License', - packages=['_cloudpickle_testpkg'], - python_requires='>=3.8', + name="cloudpickle_testpkg", + version="0.0.0", + description="Package used only for cloudpickle testing purposes", + author="Cloudpipe", + author_email="cloudpipe@googlegroups.com", + license="BSD 3-Clause License", + packages=["_cloudpickle_testpkg"], + python_requires=">=3.8", ) diff --git a/tests/generate_old_pickles.py b/tests/generate_old_pickles.py index d91aad6e..ff807770 100644 --- a/tests/generate_old_pickles.py +++ b/tests/generate_old_pickles.py @@ -8,6 +8,7 @@ active cloudpickle branch to make sure that cloudpickle is able to depickle old cloudpickle files. """ + import sys from pathlib import Path diff --git a/tests/mock_local_folder/mod.py b/tests/mock_local_folder/mod.py index 1a1c1da4..517d5013 100644 --- a/tests/mock_local_folder/mod.py +++ b/tests/mock_local_folder/mod.py @@ -5,6 +5,7 @@ reference should instead flagged to cloudpickle for pickling by value: this is done using the register_pickle_by_value api exposed by cloudpickle. """ + import typing diff --git a/tests/test_backward_compat.py b/tests/test_backward_compat.py index 1abb3da4..1d1d70a9 100644 --- a/tests/test_backward_compat.py +++ b/tests/test_backward_compat.py @@ -9,6 +9,7 @@ few canonical use cases. Cloudpicke backward-compatitibility support remains a best-effort initiative. """ + import pickle import pytest diff --git a/tests/testutils.py b/tests/testutils.py index 649cceaa..4a23f5b4 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -225,11 +225,11 @@ def check_determinist_pickle(a, b): with io.StringIO() as out: pickletools.dis(pickletools.optimize(a), out) a_out = out.getvalue() - a_out = '\n'.join(ll[11:] for ll in a_out.splitlines()) + a_out = "\n".join(ll[11:] for ll in a_out.splitlines()) with io.StringIO() as out: pickletools.dis(pickletools.optimize(b), out) b_out = out.getvalue() - b_out = '\n'.join(ll[11:] for ll in b_out.splitlines()) + b_out = "\n".join(ll[11:] for ll in b_out.splitlines()) assert a_out == b_out