Author Pam.McANulty
Recipients Pam.McANulty, fdrake, pitrou
Date 2013-04-15.14:28:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1366036133.81.0.331247983009.issue17530@psf.upfronthosting.co.za>
In-reply-to
Content
- eval expects bytes to have a continuation character and test_str_wrap did an eval check so I figured test_bytes_wrap should as well:

# repr some bytes:
>>> b = b"\x00\xff" * 5
>>> b
b'\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff'
>>> r = repr(b)
>>> r
"b'\\x00\\xff\\x00\\xff\\x00\\xff\\x00\\xff\\x00\\xff'"
>>> eval(r)
b'\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff'

# hand-wrap it without the continuation character and it fails to eval (stuck the 
>>> s = "b'\\x00\\xff\\x00\\xff\\x00'\nb'\\xff\\x00\\xff\\x00\\xff'"
>>> print(s)
b'\x00\xff\x00\xff\x00'
b'\xff\x00\xff\x00\xff'
>>> eval(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 2
    b'\xff\x00\xff\x00\xff'
                          ^
SyntaxError: invalid syntax

# stick the continuation character in, and it evals properly
>>> s = s.replace("\n", "\\\n")
>>> print(s)
b'\x00\xff\x00\xff\x00'\
b'\xff\x00\xff\x00\xff'
>>> eval(s)
b'\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff'

- I agree about the len v _len, but figured this wasn't all that foolish a consistency issue (i.e. the rest of pprint.py used _len)

- I also wanted to refactor _str_parts and _bytes_parts, but couldn't decide on the best course.  I was favoring a helper function to run the common loop since the two "if issubclass..." calls were so different and parameterizing the differences felt like it would obfuscate things too much.

- I also agree on the doc.  I figured I'd see if there weren't any hidden surprises with the patch before I worked on better doc.
History
Date User Action Args
2013-04-15 14:28:53Pam.McANultysetrecipients: + Pam.McANulty, fdrake, pitrou
2013-04-15 14:28:53Pam.McANultysetmessageid: <1366036133.81.0.331247983009.issue17530@psf.upfronthosting.co.za>
2013-04-15 14:28:53Pam.McANultylinkissue17530 messages
2013-04-15 14:28:53Pam.McANultycreate