comparison mercurial/extensions.py @ 34048: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
comparison
equal deleted inserted replaced
34047:b2c691d75d93 34048:0e0ac8f09048
131 if getattr(f, '_deprecatedregistrar', False): 131 if getattr(f, '_deprecatedregistrar', False):
132 ui.deprecwarn("cmdutil.command is deprecated, use " 132 ui.deprecwarn("cmdutil.command is deprecated, use "
133 "registrar.command to register '%s'" % c, '4.6') 133 "registrar.command to register '%s'" % c, '4.6')
134 missing = [a for a in _cmdfuncattrs if not util.safehasattr(f, a)] 134 missing = [a for a in _cmdfuncattrs if not util.safehasattr(f, a)]
135 if not missing: 135 if not missing:
136 for option in e[1]:
137 default = option[2]
138 if isinstance(default, type(u'')):
139 raise error.ProgrammingError(
140 "option '%s.%s' has a unicode default value"
141 % (c, option[1]),
142 hint=("change the %s.%s default value to a "
143 "non-unicode string" % (c, option[1])))
136 continue 144 continue
137 raise error.ProgrammingError( 145 raise error.ProgrammingError(
138 'missing attributes: %s' % ', '.join(missing), 146 'missing attributes: %s' % ', '.join(missing),
139 hint="use @command decorator to register '%s'" % c) 147 hint="use @command decorator to register '%s'" % c)
140 148