[PATCH] util: explicitly tests for None

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Mar 16 18:16:01 UTC 2017


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1489615634 25200
#      Wed Mar 15 15:07:14 2017 -0700
# Node ID 4f99a4fb0482a44178f96c29678ef4630056ff4e
# Parent  a5bad127128d8f60060be53d161acfa7a32a17d5
# EXP-Topic mutable-default
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 4f99a4fb0482
util: explicitly tests for None

Changeset 8b6927eb7efd removed the mutable default value, but did not explicitly
tested for None. Such implicit checking can introduce semantic and performance
issue. We move to an explicit check for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1831,7 +1831,8 @@ def parsetimezone(s):
 def strdate(string, format, defaults=None):
     """parse a localized time string and return a (unixtime, offset) tuple.
     if the string cannot be parsed, ValueError is raised."""
-    defaults = defaults or {}
+    if defaults is None:
+        defaults = {}
 
     # NOTE: unixtime = localunixtime + offset
     offset, date = parsetimezone(string)


More information about the Mercurial-devel mailing list