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.
--- a/mercurial/ui.py Sat Jun 17 12:52:16 2017 +0200
+++ b/mercurial/ui.py Sat Jun 17 12:52:31 2017 +0200
@@ -539,7 +539,7 @@
% (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
@@ -551,7 +551,7 @@
>>> 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):
@@ -563,9 +563,9 @@
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):