[Python-checkins] r60207 - in python/trunk: Doc/library/pprint.rst Lib/pprint.py Misc/NEWS
Guido van Rossum
guido at python.org
Wed Jan 23 01:27:50 CET 2008
On Jan 22, 2008 4:04 PM, raymond.hettinger <python-checkins at python.org> wrote:
> Author: raymond.hettinger
> Date: Wed Jan 23 01:04:40 2008
> New Revision: 60207
>
> Modified:
> python/trunk/Doc/library/pprint.rst
> python/trunk/Lib/pprint.py
> python/trunk/Misc/NEWS
> Log:
> Let pprint() support sets and frozensets (suggested by David Mertz).
Kewl! Some 3.0 notes below.
> Modified: python/trunk/Doc/library/pprint.rst
> ==============================================================================
> --- python/trunk/Doc/library/pprint.rst (original)
> +++ python/trunk/Doc/library/pprint.rst Wed Jan 23 01:04:40 2008
> @@ -25,6 +25,9 @@
> dictionary was sorted only if its display required more than one line, although
> that wasn't documented.
>
> +.. versionchanged:: 2.6
> + Added support for :class:`set` and :class:`frozenset`.
> +
> The :mod:`pprint` module defines one class:
>
> .. First the implementation class:
>
> Modified: python/trunk/Lib/pprint.py
> ==============================================================================
> --- python/trunk/Lib/pprint.py (original)
> +++ python/trunk/Lib/pprint.py Wed Jan 23 01:04:40 2008
> @@ -162,11 +162,24 @@
> write('}')
> return
>
> - if (issubclass(typ, list) and r is list.__repr__) or \
> - (issubclass(typ, tuple) and r is tuple.__repr__):
> + if ((issubclass(typ, list) and r is list.__repr__) or
> + (issubclass(typ, tuple) and r is tuple.__repr__) or
> + (issubclass(typ, set) and r is set.__repr__) or
> + (issubclass(typ, frozenset) and r is frozenset.__repr__)
> + ):
> if issubclass(typ, list):
> write('[')
> endchar = ']'
> + elif issubclass(typ, set):
> + write('set([')
> + endchar = '])'
> + object = sorted(object)
> + indent += 4
Warning: this should be done differently in 3.0 -- if the set is
non-empty, it should write '{' and set endchar to '}'. And indent
should vary accordingly. An empty set could be shortened to 'set()'
instead of 'set([])'.
> + elif issubclass(typ, frozenset):
> + write('frozenset([')
> + endchar = '])'
> + object = sorted(object)
> + indent += 9
And here, if the set is non-empty, write 'frozenset({' and set endchar
to '})'; if it is empty, use 'frozenset()' if possible.
> else:
> write('(')
> endchar = ')'
>
> Modified: python/trunk/Misc/NEWS
> ==============================================================================
> --- python/trunk/Misc/NEWS (original)
> +++ python/trunk/Misc/NEWS Wed Jan 23 01:04:40 2008
> @@ -378,6 +378,8 @@
> Library
> -------
>
> +- The pprint module now supports sets and frozensets.
> +
> - #1221598: add optional callbacks to ftplib.FTP's storbinary() and
> storlines() methods. (Contributed by Phil Schwartz)
>
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-checkins
mailing list