Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pprint not handline uncomparable dictionary keys, set members well #66907

Closed
AndreasKostyrka mannequin opened this issue Oct 24, 2014 · 4 comments
Closed

pprint not handline uncomparable dictionary keys, set members well #66907

AndreasKostyrka mannequin opened this issue Oct 24, 2014 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@AndreasKostyrka
Copy link
Mannequin

AndreasKostyrka mannequin commented Oct 24, 2014

BPO 22718
Nosy @rhettinger, @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2014-11-01.08:02:13.899>
created_at = <Date 2014-10-24.15:47:29.092>
labels = ['type-bug', 'library']
title = 'pprint not handline uncomparable dictionary keys, set members well'
updated_at = <Date 2014-11-01.08:02:13.897>
user = 'https://bugs.python.org/AndreasKostyrka'

bugs.python.org fields:

activity = <Date 2014-11-01.08:02:13.897>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = <Date 2014-11-01.08:02:13.899>
closer = 'rhettinger'
components = ['Library (Lib)']
creation = <Date 2014-10-24.15:47:29.092>
creator = 'Andreas.Kostyrka'
dependencies = []
files = []
hgrepos = []
issue_num = 22718
keywords = []
message_count = 4.0
messages = ['229934', '229935', '229937', '230432']
nosy_count = 3.0
nosy_names = ['rhettinger', 'r.david.murray', 'Andreas.Kostyrka']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue22718'
versions = ['Python 2.7']

@AndreasKostyrka
Copy link
Mannequin Author

AndreasKostyrka mannequin commented Oct 24, 2014

>> import datetime, pprint
>> pprint.pformat({datetime.datetime.now(): 1, None: 1})

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/pprint.py", line 63, in pformat
    return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object)
  File "/usr/lib/python2.7/pprint.py", line 122, in pformat
    self._format(object, sio, 0, 0, {}, 0)
  File "/usr/lib/python2.7/pprint.py", line 140, in _format
    rep = self._repr(object, context, level - 1)
  File "/usr/lib/python2.7/pprint.py", line 226, in _repr
    self._depth, level)
  File "/usr/lib/python2.7/pprint.py", line 238, in format
    return _safe_repr(object, context, maxlevels, level)
  File "/usr/lib/python2.7/pprint.py", line 280, in _safe_repr
    for k, v in _sorted(object.items()):
  File "/usr/lib/python2.7/pprint.py", line 82, in _sorted
    return sorted(iterable)
TypeError: can't compare datetime.datetime to NoneType

This is issue is kind of related to http://bugs.python.org/issue14998
but that talks only python 3.2+

@AndreasKostyrka AndreasKostyrka mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 24, 2014
@AndreasKostyrka
Copy link
Mannequin Author

AndreasKostyrka mannequin commented Oct 24, 2014

This also applies to sets.

@AndreasKostyrka AndreasKostyrka mannequin changed the title pprint not handline uncomparable dictionary keys well pprint not handline uncomparable dictionary keys, set members well Oct 24, 2014
@bitdancer
Copy link
Member

Actually, it applies to datetime, which is is almost unique among python2 datatypes in not being comparable to other types by default. I'm not sure this is worth fixing in 2.7.

@rhettinger
Copy link
Contributor

Complex numbers also aren't sortable.

I'm not sure this is worth fixing in 2.7.

I agree. That ship sailed a long time ago.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants