[PATCH 2 of 2] extensions: pass ui arguement to extsetup if accepted

Martin Geisler mg at lazybytes.net
Thu Aug 27 02:41:25 CDT 2009


Dirkjan Ochtman <dirkjan at ochtman.nl> writes:

> On Wed, Aug 26, 2009 at 23:02, Simon Heimberg<simohe at besonet.ch> wrote:
>> # HG changeset patch
>> # User Simon Heimberg <simohe at besonet.ch>
>> # Date 1250376084 -7200
>> # Node ID 5f4e2711e3b2f1de44ce92616be43c5aa38e3e77
>> # Parent  51ca46023b3844b11ee304555ac6f23b7581d67c
>> extensions: pass ui arguement to extsetup if accepted
>>
>> diff -r 51ca46023b38 -r 5f4e2711e3b2 mercurial/extensions.py
>> --- a/mercurial/extensions.py   Son Aug 16 00:41:14 2009 +0200
>> +++ b/mercurial/extensions.py   Son Aug 16 00:41:24 2009 +0200
>> @@ -117,7 +117,12 @@
>>     for name, mod in unloaded:
>>         extsetup = getattr(mod, 'extsetup', None)
>>         if extsetup:
>> -            extsetup()
>> +            try:
>> +                extsetup(ui)
>> +            except TypeError:
>> +                if extsetup.func_code.co_argcount != 0:
>> +                    raise
>> +                extsetup() # old extsetup with no ui argument
>
> Why the try-except this way? Couldn't it just be
>
> if extsetup.func_code.co_argcount:
>     extsetup(ui)
> else:
>     extsetup()

We also have the util.checksignature function, which looks like it's
meant for things like this.

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.



More information about the Mercurial-devel mailing list