Skip to content

Commit

Permalink
CLN blackify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomMoral committed Nov 12, 2023
1 parent f16a63f commit 124826b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 30 deletions.
8 changes: 4 additions & 4 deletions ci/install_coverage_subprocess_pth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions cloudpickle/cloudpickle_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
See: tests/test_backward_compat.py
"""

from . import cloudpickle


Expand Down
19 changes: 12 additions & 7 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -2000,17 +2002,16 @@ 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))

# 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)
Expand All @@ -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):
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion tests/cloudpickle_testpkg/_cloudpickle_testpkg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
12 changes: 4 additions & 8 deletions tests/cloudpickle_testpkg/_cloudpickle_testpkg/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/cloudpickle_testpkg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
1 change: 1 addition & 0 deletions tests/generate_old_pickles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/mock_local_folder/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions tests/test_backward_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
few canonical use cases. Cloudpicke backward-compatitibility support remains a
best-effort initiative.
"""

import pickle

import pytest
Expand Down
4 changes: 2 additions & 2 deletions tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 124826b

Please sign in to comment.