Patchwork [1,of,4] templater: make it clearer that _flatten() omits None

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 21, 2016, 2:53 p.m.
Message ID <7e4ca26412a04f858f31.1471791235@mimosa>
Download mbox | patch
Permalink /patch/16372/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 21, 2016, 2:53 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1471503307 -32400
#      Thu Aug 18 15:55:07 2016 +0900
# Node ID 7e4ca26412a04f858f31f7c409734eb935a3586f
# Parent  5f86818c95e5ea59c48dfceca2e286cd11f9a800
templater: make it clearer that _flatten() omits None

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -917,17 +917,19 @@  def _flatten(thing):
     '''yield a single stream from a possibly nested set of iterators'''
     if isinstance(thing, str):
         yield thing
+    elif thing is None:
+        pass
     elif not util.safehasattr(thing, '__iter__'):
-        if thing is not None:
-            yield str(thing)
+        yield str(thing)
     else:
         for i in thing:
             if isinstance(i, str):
                 yield i
+            elif i is None:
+                pass
             elif not util.safehasattr(i, '__iter__'):
-                if i is not None:
-                    yield str(i)
-            elif i is not None:
+                yield str(i)
+            else:
                 for j in _flatten(i):
                     yield j