Skip to content
Closed
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
6 changes: 5 additions & 1 deletion q.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
class Q(object):
__doc__ = __doc__ # from the module's __doc__ above

import ast, code, inspect, os, pydoc, sys, random, re, time
import ast, code, inspect, os, pydoc, sys, random, re, time, pprint

# The debugging log will go to this file; temporary files will also have
# this path as a prefix, followed by a random number.
Expand Down Expand Up @@ -159,6 +159,10 @@ def safe_repr(self, value):
# TODO: Use colour to distinguish '...' elision from actual '...' chars.
# TODO: Show a nicer repr for SRE.Match objects.
# TODO: Show a nicer repr for big multiline strings.
# Use pretty print for dictionaries
if isinstance(value, dict) or isinstance(value, list):
pp = self.pprint.PrettyPrinter(indent=0)
return pp.pformat(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dictionaries can be large so instead of returning here, I'd set value = pp.pformat(value)

Then value will be shortened if necessary by self.TEXT_REPR.repr() for inclusion in /tmp/q and the full value of value will be placed in a file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we send to an external file, probably okay to leave an indent of 1 or 2 :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. but TextRepr.repr ends up escaping the pprint formatting which is not desirable. So it's not quite that simple :-(

result = self.TEXT_REPR.repr(value)
if isinstance(value, basestring) and len(value) > 80:
# If the string is big, save it to a file for later examination.
Expand Down