pprintpp icon indicating copy to clipboard operation
pprintpp copied to clipboard

Frozenset bug.

Open jonathanslenders opened this issue 11 years ago • 7 comments

pprintpp.pprint({6,frozenset({78, 32, 342}),8})

fails with

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jonathan/.virtualenvs/.../local/lib/python2.7/site-packages/pprintpp.py", line 94, in pprint
    printer.pprint(object)
  File "/home/jonathan/.virtualenvs/.../local/lib/python2.7/site-packages/pprintpp.py", line 236, in pprint
    self._format(object, state)
  File "/home/jonathan/.virtualenvs/.../local/lib/python2.7/site-packages/pprintpp.py", line 349, in _format
    self._format_nested_objects(object, state, typeish=typeish)
  File "/home/jonathan/.virtualenvs/.../local/lib/python2.7/site-packages/pprintpp.py", line 280, in _format_nested_objects
    oneline=True)
  File "/home/jonathan/.virtualenvs/.../local/lib/python2.7/site-packages/pprintpp.py", line 310, in _write_nested_real
    object = _sorted(object)
  File "/home/jonathan/.virtualenvs/.../local/lib/python2.7/site-packages/pprintpp.py", line 117, in _sorted
    return sorted(iterable)
TypeError: can only compare to a set

(I didn't had time to look further into this issue.)

jonathanslenders avatar Sep 10 '14 13:09 jonathanslenders

Weird. I can't recreate that on any of the supported Pythons (2.7, 3.3, PyPy). What's in the set?

wolever avatar Sep 10 '14 14:09 wolever

Disregard that, I'm an idiot. The issue is that sets can't be compared to non-set things. Testing for this also uncovered a related issue: python 3 gets fussy when trying to sort heterogeneous sets. Fix incoming!

wolever avatar Sep 10 '14 14:09 wolever

Okay! I've put https://github.com/wolever/safesort out there for comments, and I'll use it for sorting here too once I've got some confirmation that it's not a totally insane thing to do.

wolever avatar Sep 10 '14 16:09 wolever

ok, nice. :) btw, is it impossible to establish without the exec in safesort?

jonathanslenders avatar Sep 10 '14 17:09 jonathanslenders

On 2014-09-10, at 1:56 PM, Jonathan Slenders [email protected] wrote:

ok, nice. :) btw, is it impossible to establish without the exec in safesort?

Ya, safesort would definitely be possible to implement without exec; there would just be a lot of code duplication, or a pile of less performant function calls. What's the concern about it?=

wolever avatar Sep 10 '14 18:09 wolever

No real concern, it could be a valid use case. Only it feels like going back in time and have code preprocessors and macros like in C. :)

jonathanslenders avatar Sep 10 '14 19:09 jonathanslenders

On 2014-09-10, at 3:23 PM, Jonathan Slenders [email protected] wrote:

No real concern, it could be a valid use case. Only it feels like going back in time and have code preprocessors and macros like in C. :)

That is precisely what it is ;)

Python is wonderful for many things, but it does fall a bit short in preprocessing department :(=

wolever avatar Sep 10 '14 19:09 wolever