fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] [patch] better error reporting on state


From: Jorge Vargas
Subject: Re: [Fab-user] [patch] better error reporting on state
Date: Thu, 21 May 2009 09:02:56 -0400

hi Christian

On Thu, May 21, 2009 at 4:36 AM, Christian Vest Hansen
<address@hidden> wrote:
> Why did you turn the if..else into a try..except ?
>
duck typing :)
it's also a small performance increase as the old way was going to the
dict twice, but the real patch is to display the error attribute
instead of just saying it one line above.


> On Thu, May 21, 2009 at 5:00 AM, Jorge Vargas <address@hidden> wrote:
>> I'm sorry I'm a git noob and I still don't know how it works... Why
>> can't it be more predictable like mercurial :p
>>
>> This is a tiny patch to provide a better implementation for
>> __getattr__ it will produce a more obvious error message.
>>
>> diff --git a/fabric/state.py b/fabric/state.py
>> index 270f56f..a1f3600 100644
>> --- a/fabric/state.py
>> +++ b/fabric/state.py
>> @@ -58,10 +58,11 @@ class _AttributeDict(dict):
>>
>>     """
>>     def __getattr__(self, key):
>> -        if key in self:
>> +        try:
>>             return self[key]
>> -        else:
>> -            raise AttributeError # to conform with __getattr__ spec
>> +        except KeyError:
>> +            # to conform with __getattr__ spec
>> +            raise AttributeError(key)
>>
>>     def __setattr__(self, key, value):
>>         self[key] = value
>>
>> Last thread for the day :p
>>
>>
>> _______________________________________________
>> Fab-user mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/fab-user
>>
>
>
>
> --
> Venlig hilsen / Kind regards,
> Christian Vest Hansen.
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]