Mercurial > public > mercurial-scm > hg-stable
diff mercurial/extensions.py @ 34065:0e0ac8f09048
extensions: prohibit unicode defaults
If the default value of an option is a unicode string (something
than happen easily when using a 'from __future__ import unicode_literals'),
any value passed on the command line will be ignored because the fancyopts
module only checks for byte strings and not unicode strings.
Changing fancyopts behavior is easy but would make assumptions on how
the python3 port should be done, which is outside the scope of this patch.
The chosen approach is to stop an extension from being loaded when a unicode
default value is detected, with a hint for the developer.
author | Christophe de Vienne <christophe@cdevienne.info> |
---|---|
date | Tue, 29 Aug 2017 18:24:51 +0200 |
parents | 47e52f079a57 |
children | 5361771f9714 |
line wrap: on
line diff
--- a/mercurial/extensions.py Sat Aug 19 22:04:03 2017 +0900 +++ b/mercurial/extensions.py Tue Aug 29 18:24:51 2017 +0200 @@ -133,6 +133,14 @@ "registrar.command to register '%s'" % c, '4.6') missing = [a for a in _cmdfuncattrs if not util.safehasattr(f, a)] if not missing: + for option in e[1]: + default = option[2] + if isinstance(default, type(u'')): + raise error.ProgrammingError( + "option '%s.%s' has a unicode default value" + % (c, option[1]), + hint=("change the %s.%s default value to a " + "non-unicode string" % (c, option[1]))) continue raise error.ProgrammingError( 'missing attributes: %s' % ', '.join(missing),