Skip to content

Commit 2322668

Browse files
Remove unneeded pprint interfaces
There are parts of the original pprint module that we won't need, let's limit the surface and remove the unnecessary code
1 parent eb6ad08 commit 2322668

File tree

1 file changed

+2
-77
lines changed

1 file changed

+2
-77
lines changed

src/_pytest/_io/pprint.py

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -6,85 +6,22 @@
66
# flake8: noqa
77
# type: ignore
88

9-
#
10-
# Author: Fred L. Drake, Jr.
11-
9+
# Original Author: Fred L. Drake, Jr.
10+
1211
#
1312
# This is a simple little module I wrote to make life easier. I didn't
1413
# see anything quite like it in the library, though I may have overlooked
1514
# something. I wrote this when I was trying to read some heavily nested
1615
# tuples with fairly non-descriptive content. This is modeled very much
1716
# after Lisp/Scheme - style pretty-printing of lists. If you find it
1817
# useful, thank small children who sleep at night.
19-
20-
"""Support to pretty-print lists, tuples, & dictionaries recursively.
21-
22-
Very simple, but useful, especially in debugging data structures.
23-
24-
Classes
25-
-------
26-
27-
PrettyPrinter()
28-
Handle pretty-printing operations onto a stream using a configured
29-
set of formatting parameters.htop
30-
31-
Functions
32-
---------
33-
34-
pformat()
35-
Format a Python object into a pretty-printed representation.
36-
37-
pprint()
38-
Pretty-print a Python object to a stream [default is sys.stdout].
39-
40-
saferepr()
41-
Generate a 'standard' repr()-like value, but protect against recursive
42-
data structures.
43-
44-
"""
45-
4618
import collections as _collections
4719
import dataclasses as _dataclasses
4820
import re
4921
import sys as _sys
5022
import types as _types
5123
from io import StringIO as _StringIO
5224

53-
__all__ = ["pprint","pformat","isreadable","isrecursive","saferepr",
54-
"PrettyPrinter", "pp"]
55-
56-
57-
def pprint(object, stream=None, indent=1, width=80, depth=None, *,
58-
compact=False, sort_dicts=True, underscore_numbers=False):
59-
"""Pretty-print a Python object to a stream [default is sys.stdout]."""
60-
printer = PrettyPrinter(
61-
stream=stream, indent=indent, width=width, depth=depth,
62-
compact=compact, sort_dicts=sort_dicts,
63-
underscore_numbers=underscore_numbers)
64-
printer.pprint(object)
65-
66-
def pformat(object, indent=1, width=80, depth=None, *,
67-
compact=False, sort_dicts=True, underscore_numbers=False):
68-
"""Format a Python object into a pretty-printed representation."""
69-
return PrettyPrinter(indent=indent, width=width, depth=depth,
70-
compact=compact, sort_dicts=sort_dicts,
71-
underscore_numbers=underscore_numbers).pformat(object)
72-
73-
def pp(object, *args, sort_dicts=False, **kwargs):
74-
"""Pretty-print a Python object"""
75-
pprint(object, *args, sort_dicts=sort_dicts, **kwargs)
76-
77-
def saferepr(object):
78-
"""Version of repr() which can handle recursive data structures."""
79-
return PrettyPrinter()._safe_repr(object, {}, None, 0)[0]
80-
81-
def isreadable(object):
82-
"""Determine if saferepr(object) is readable by eval()."""
83-
return PrettyPrinter()._safe_repr(object, {}, None, 0)[1]
84-
85-
def isrecursive(object):
86-
"""Determine if object requires a recursive representation."""
87-
return PrettyPrinter()._safe_repr(object, {}, None, 0)[2]
8825

8926
class _safe_key:
9027
"""Helper function for key functions when sorting unorderable objects.
@@ -157,23 +94,11 @@ def __init__(self, indent=1, width=80, depth=None, stream=None, *,
15794
self._sort_dicts = sort_dicts
15895
self._underscore_numbers = underscore_numbers
15996

160-
def pprint(self, object):
161-
if self._stream is not None:
162-
self._format(object, self._stream, 0, 0, {}, 0)
163-
self._stream.write("\n")
164-
16597
def pformat(self, object):
16698
sio = _StringIO()
16799
self._format(object, sio, 0, 0, {}, 0)
168100
return sio.getvalue()
169101

170-
def isrecursive(self, object):
171-
return self.format(object, {}, 0, 0)[2]
172-
173-
def isreadable(self, object):
174-
s, readable, recursive = self.format(object, {}, 0, 0)
175-
return readable and not recursive
176-
177102
def _format(self, object, stream, indent, allowance, context, level):
178103
objid = id(object)
179104
if objid in context:

0 commit comments

Comments
 (0)