From 4e20d0e711aeaf509943e1493ca62ad808d413ea 2006-07-13 19:31:22 From: walter.doerwald Date: 2006-07-13 19:31:22 Subject: [PATCH] Make isort usable without a key argument. This sorts the items themselves. --- diff --git a/IPython/Extensions/ipipe.py b/IPython/Extensions/ipipe.py index e9bd118..7b9b37d 100644 --- a/IPython/Extensions/ipipe.py +++ b/IPython/Extensions/ipipe.py @@ -1511,18 +1511,24 @@ class isort(Pipe): >>> ils | isort("_.isdir(), _.lower()", reverse=True) """ - def __init__(self, key, globals=None, reverse=False): + def __init__(self, key=None, globals=None, reverse=False): """ Create an ``isort`` object. ``key`` can be a callable or a string - containing an expression. If ``reverse`` is true the sort order will - be reversed. For the meaning of ``globals`` see ``ifilter``. + containing an expression (or ``None`` in which case the items + themselves will be sorted). If ``reverse`` is true the sort order + will be reversed. For the meaning of ``globals`` see ``ifilter``. """ self.key = key self.globals = globals self.reverse = reverse def __xiter__(self, mode): - if callable(self.key): + if self.key is None: + items = sorted( + xiter(self.input, mode), + reverse=self.reverse + ) + elif callable(self.key): items = sorted( xiter(self.input, mode), key=self.key, diff --git a/doc/ChangeLog b/doc/ChangeLog index b825e26..3c4af84 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2006-07-13 Walter Doerwald + + * IPython/Extensions/ipipe.py (isort): Make isort usable without + argument. This sorts the items themselves. + 2006-07-12 Walter Doerwald * IPython/Extensions/ipipe.py (eval, ifilter, isort, ieval):