Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: reformat-pyproject

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -32,7 +32,7 @@ repos:
- id: end-of-file-fixer

- repo: https://github.com/domdfcoding/pre-commit-hooks
rev: v0.6.0
rev: v0.7.0
hooks:
- id: requirements-txt-sorter
args:
Expand Down Expand Up @@ -60,26 +60,26 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/python-formate/pyupgrade
rev: bbe3007
rev: v3.3.0
hooks:
- id: pyupgrade
args:
- --py37-plus
- --keep-runtime-typing

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.1
rev: v1.5.6
hooks:
- id: remove-crlf
- id: forbid-crlf

- repo: https://github.com/python-formate/snippet-fmt
rev: v0.1.5
rev: v0.2.0
hooks:
- id: snippet-fmt

- repo: https://github.com/python-formate/formate
rev: v1.2.0
rev: v1.2.1
hooks:
- id: formate
exclude: ^(doc-source/conf|__pkginfo__|setup)\.(_)?py$
Expand Down
24 changes: 14 additions & 10 deletions pprint36/_pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@


def pprint(object, stream=None, indent=1, width=80, depth=None, *, compact=False, sort_dicts=True):
"""Pretty-print a Python object to a stream [default is sys.stdout]."""
"""Pretty-print a Python object to a stream [default is sys.stdout].
"""
printer = PrettyPrinter(
stream=stream,
indent=indent,
Expand All @@ -57,7 +58,8 @@ def pprint(object, stream=None, indent=1, width=80, depth=None, *, compact=False


def pformat(object, indent=1, width=80, depth=None, *, compact=False, sort_dicts=True):
"""Format a Python object into a pretty-printed representation."""
"""Format a Python object into a pretty-printed representation.
"""
return PrettyPrinter(
indent=indent,
width=width,
Expand All @@ -68,22 +70,26 @@ def pformat(object, indent=1, width=80, depth=None, *, compact=False, sort_dicts


def pp(object, *args, sort_dicts=False, **kwargs):
"""Pretty-print a Python object"""
"""Pretty-print a Python object
"""
pprint(object, *args, sort_dicts=sort_dicts, **kwargs)


def saferepr(object):
"""Version of repr() which can handle recursive data structures."""
"""Version of repr() which can handle recursive data structures.
"""
return _safe_repr(object, {}, None, 0, True)[0]


def isreadable(object):
"""Determine if saferepr(object) is readable by eval()."""
"""Determine if saferepr(object) is readable by eval().
"""
return _safe_repr(object, {}, None, 0, True)[1]


def isrecursive(object):
"""Determine if object requires a recursive representation."""
"""Determine if object requires a recursive representation.
"""
return _safe_repr(object, {}, None, 0, True)[2]


Expand All @@ -94,8 +100,7 @@ class _safe_key:
unorderable types (sorting first comparing the type name and then by
the obj ids). Does not work recursively, so dict.items() must have
_safe_key applied to both the key and the value.

"""
"""

__slots__ = ["obj"]

Expand Down Expand Up @@ -138,8 +143,7 @@ def __init__(self, indent=1, width=80, depth=None, stream=None, *, compact=False

sort_dicts
If true, dict keys are sorted.

"""
"""
indent = int(indent)
width = int(width)
if indent < 0:
Expand Down
15 changes: 10 additions & 5 deletions tests/_test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@
def test_pickling(self):
for i in range(pickle.HIGHEST_PROTOCOL + 1):
p = pickle.dumps(self.s, i)
dup = pickle.loads(p)

Check warning on line 246 in tests/_test_set.py

View check run for this annotation

codefactor.io / CodeFactor

tests/_test_set.py#L246

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue. (B301)
self.assertEqual(self.s, dup, f"{self.s} != {dup}")
if type(self.s) not in (set, frozenset):
self.s.x = 10
p = pickle.dumps(self.s, i)
dup = pickle.loads(p)

Check warning on line 251 in tests/_test_set.py

View check run for this annotation

codefactor.io / CodeFactor

tests/_test_set.py#L251

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue. (B301)
self.assertEqual(self.s.x, dup.x)

def test_iterator_pickling(self):
Expand All @@ -256,20 +256,20 @@
itorg = iter(self.s)
data = self.thetype(self.s)
d = pickle.dumps(itorg, proto)
it = pickle.loads(d)

Check warning on line 259 in tests/_test_set.py

View check run for this annotation

codefactor.io / CodeFactor

tests/_test_set.py#L259

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue. (B301)
# Set iterators unpickle as list iterators due to the
# undefined order of set items.
# self.assertEqual(type(itorg), type(it))
self.assertIsInstance(it, collections.abc.Iterator)
self.assertEqual(self.thetype(it), data)

it = pickle.loads(d)

Check warning on line 266 in tests/_test_set.py

View check run for this annotation

codefactor.io / CodeFactor

tests/_test_set.py#L266

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue. (B301)
try:
drop = next(it)
except StopIteration:
continue
d = pickle.dumps(it, proto)
it = pickle.loads(d)

Check warning on line 272 in tests/_test_set.py

View check run for this annotation

codefactor.io / CodeFactor

tests/_test_set.py#L272

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue. (B301)
self.assertEqual(self.thetype(it), data - self.thetype((drop, )))

def test_deepcopy(self):
Expand Down Expand Up @@ -954,7 +954,7 @@
def test_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
p = pickle.dumps(self.set, proto)
copy = pickle.loads(p)

Check warning on line 957 in tests/_test_set.py

View check run for this annotation

codefactor.io / CodeFactor

tests/_test_set.py#L957

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue. (B301)
self.assertEqual(self.set, copy, f"{self.set} != {copy}")

def test_issue_37219(self):
Expand Down Expand Up @@ -1099,7 +1099,8 @@


class TestExceptionPropagation(unittest.TestCase):
"""SF 628246: Set constructor should not trap iterator TypeErrors"""
"""SF 628246: Set constructor should not trap iterator TypeErrors
"""

def test_instanceWithException(self):
self.assertRaises(TypeError, set, baditer())
Expand Down Expand Up @@ -1990,7 +1991,8 @@


class TestOperationsMutating:
"""Regression test for bpo-46615"""
"""Regression test for bpo-46615
"""

constructor1 = None
constructor2 = None
Expand Down Expand Up @@ -2202,7 +2204,8 @@


def powerset(U):
"""Generates all subsets of a set or sequence U."""
"""Generates all subsets of a set or sequence U.
"""
U = iter(U)
try:
x = frozenset([next(U)])
Expand All @@ -2214,15 +2217,17 @@


def cube(n):
"""Graph of n-dimensional hypercube."""
"""Graph of n-dimensional hypercube.
"""
singletons = [frozenset([x]) for x in range(n)]
return {x: frozenset([x ^ s for s in singletons]) for x in powerset(range(n))}


def linegraph(G):
"""Graph, the vertices of which are edges of G,
with two vertices being adjacent iff the corresponding
edges share a vertex."""
edges share a vertex.
"""
L = {}
for x in G:
for y in G[x]:
Expand Down
Loading