diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-01-11 16:24:02 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2017-01-11 16:36:58 -0800 |
commit | f39bd61e279ead7106a1272b653bc2e64c6fd452 (patch) | |
tree | 4ddec18322b5304daef3e10a55ad89fd8d52f10f /alot | |
parent | 4645c4b2eb2b3aa93305f0c10fd3567cfeeb41c7 (diff) |
Replace None passed to comprehensions with identity function
One of the differences between map/filter and a comprehension is what
happens with None. For map and filter passing None as the function will
be treated as an identity function (equivalent to lambda x: x), for
comprehensions however, this will raise an exception (calling NoneType).
The fix is rather simple, instead of making the default of filtfun None,
make it an identity function. I've used lambda x: x since it's easy,
although defining an identity function in a utility library might be
preferable since lambdas are slower than normal functions.
Fixes #946
Diffstat (limited to 'alot')
-rw-r--r-- | alot/buffers.py | 4 | ||||
-rw-r--r-- | alot/commands/globals.py | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/alot/buffers.py b/alot/buffers.py index 9a2672b2..8dcb7352 100644 --- a/alot/buffers.py +++ b/alot/buffers.py @@ -63,7 +63,7 @@ class BufferlistBuffer(Buffer): modename = 'bufferlist' - def __init__(self, ui, filtfun=None): + def __init__(self, ui, filtfun=lambda x: x): self.filtfun = filtfun self.ui = ui self.isinitialized = False @@ -617,7 +617,7 @@ class TagListBuffer(Buffer): modename = 'taglist' - def __init__(self, ui, alltags=None, filtfun=None): + def __init__(self, ui, alltags=None, filtfun=lambda x: x): self.filtfun = filtfun self.ui = ui self.tags = alltags or [] diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 4ce07a88..a9a85cba 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -485,7 +485,7 @@ class BufferFocusCommand(Command): class OpenBufferlistCommand(Command): """open a list of active buffers""" - def __init__(self, filtfun=None, **kwargs): + def __init__(self, filtfun=lambda x: x, **kwargs): """ :param filtfun: filter to apply to displayed list :type filtfun: callable (str->bool) @@ -508,7 +508,7 @@ class OpenBufferlistCommand(Command): class TagListCommand(Command): """opens taglist buffer""" - def __init__(self, filtfun=None, tags=None, **kwargs): + def __init__(self, filtfun=lambda x: x, tags=None, **kwargs): """ :param filtfun: filter to apply to displayed list :type filtfun: callable (str->bool) |