[PATCH 1 of 2] patchbomb: prompt: always return a str, even when ui is non-interactive

Nicolas Dumazet nicdumz at gmail.com
Wed Jul 15 08:56:16 CDT 2009


yep, that got pointed out too by tonfa on IRC.

Actually, the current behavior is to do"%s" % prompt(...), which means
that when prompt returns None in non-interactive patches, subject is
"[PATCH] None" (see the test ;) )

I'll change the call to use the parameter default=''

2009/7/15 Greg Ward <greg-hg at gerg.ca>:
> On Tue, Jul 14, 2009 at 11:03 PM, Nicolas Dumazet<nicdumz at gmail.com> wrote:
>> # HG changeset patch
>> # User Nicolas Dumazet <nicdumz.commits at gmail.com>
>> # Date 1247624826 -32400
>> # Node ID 25c6fc40b705222cc9b7f88bd04e7c0638b7ad29
>> # Parent  78b81646a2e4ae31e5c814b00be7cedf427a9c63
>> patchbomb: prompt: always return a str, even when ui is non-interactive
>>
>> 'foo %s bar' % prompt(ui, ...) always work, even if prompt returns None.
>> However the result of prompt() cannot be used directly in concatenations
>> if it can be None. Let's be explicit.
>>
>> diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
>> --- a/hgext/patchbomb.py
>> +++ b/hgext/patchbomb.py
>> @@ -76,7 +76,7 @@
>>
>>  def prompt(ui, prompt, default=None, rest=': ', empty_ok=False):
>>     if not ui.interactive():
>> -        return default
>> +        return str(default)
>
> But then you'll return the string "None", which is hardly ever useful.
>  IMHO better to expect callers to check for None if they want to
> concatenate.  (Interpolating None into a %s is rarely appropriate
> either.  Any time I see a Python app say "blah blah: None blah blah",
> I know I've just seen a minor bug.)
>
> Greg
>



-- 
Nicolas Dumazet — NicDumZ [ nɪk.d̪ymz ]



More information about the Mercurial-devel mailing list