You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
plistlib.dumps() raises TypeError when skipkeys=True and dict has mixed key types #145856
When sort_keys is true (the default) the keys for dictionaries will be
written to the plist in sorted order, otherwise they will be written in
the iteration order of the dictionary.
When skipkeys is false (the default) the function raises :exc:TypeError
when a key of a dictionary is not a string, otherwise such keys are skipped.
plistlib.dumps() with skipkeys=True and sort_keys=True (the default) currently raises TypeError when the dict contains both string and non-string keys. The expected behavior per the documentation is: non-string keys are skipped, and the remaining (string) keys are written in sorted order.
Reproducer
importplistlibd= {1: 'a', 'z': 'b', 'a': 'c'}
plistlib.dumps(d, skipkeys=True)
# Raises: TypeError: '<' not supported between instances of 'str' and 'int'# Expected: valid plist with {"a": "c", "z": "b"}
Both FMT_XML and FMT_BINARY formats raise the same error.
I believe this is an implementation error rather than a documentation issue. The fix is likely to reverse the order of operations: filter non-string keys first, then sort. Happy to file a PR if confirmed a bug.
Activity
stefanzetzsche commentedon Mar 12, 2026
I believe this is an implementation error rather than a documentation issue. The fix is likely to reverse the order of operations: filter non-string keys first, then sort. Happy to file a PR if confirmed a bug.
stefanzetzsche commentedon Mar 12, 2026
For context, json has a similar issue: #69643.
pythongh-145856: Fix plistlib.dumps() skipkeys behavior with mixed ke…
pythongh-145856: Fix plistlib.dumps() skipkeys behavior with mixed ke…
pythongh-145856: Fix plistlib.dumps() skipkeys behavior with mixed ke…
pythongh-145856: Fix plistlib.dumps() skipkeys behavior with mixed ke…
gh-145856: Fix plistlib.dump() with skipkeys=True and sort_keys=True (G…
[3.14] gh-145856: Fix plistlib.dump() with skipkeys=True and sort_key…
[3.13] gh-145856: Fix plistlib.dump() with skipkeys=True and sort_key…
[3.15] gh-145856: Fix plistlib.dump() with skipkeys=True and sort_key…