Patchwork [03,of,10] config: use the new '_unset' value for 'configwith'

login
register
mail settings
Submitter Pierre-Yves David
Date June 18, 2017, 6:55 p.m.
Message ID <3984cb4c86deba1c2552.1497812113@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21481/
State Accepted
Headers show

Comments

Pierre-Yves David - June 18, 2017, 6:55 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1497696751 -7200
#      Sat Jun 17 12:52:31 2017 +0200
# Node ID 3984cb4c86deba1c255208f6c2e4a98f4aff227b
# Parent  0d7b693176387264f4e04e8ee6455195fa871e93
# EXP-Topic config.register
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 3984cb4c86de
config: use the new '_unset' value for 'configwith'

This should let 'configwith' delegate all special processing of the default
config value to the main 'config' method.

This changeset introduce a small change in behavior since the default value is
run through the 'convert' function. This does not seems harmful and no actual
test break. This small change make the code simpler so I'm keeping it.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -501,7 +501,7 @@  class ui(object):
                                     % (section, name, v))
         return b
 
-    def configwith(self, convert, section, name, default=None,
+    def configwith(self, convert, section, name, default=_unset,
                    desc=None, untrusted=False):
         """parse a configuration element with a conversion function
 
@@ -513,7 +513,7 @@  class ui(object):
         >>> u.configwith(float, s, 'float2')
         -4.25
         >>> u.configwith(float, s, 'unknown', 7)
-        7
+        7.0
         >>> u.setconfig(s, 'invalid', 'somevalue')
         >>> u.configwith(float, s, 'invalid')
         Traceback (most recent call last):
@@ -525,9 +525,9 @@  class ui(object):
         ConfigError: foo.invalid is not a valid womble ('somevalue')
         """
 
-        v = self.config(section, name, None, untrusted)
+        v = self.config(section, name, default, untrusted)
         if v is None:
-            return default
+            return v # do not attempt to convert None
         try:
             return convert(v)
         except (ValueError, error.ParseError):