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: Jeff Forcier
Subject: Re: [Fab-user] [patch] better error reporting on state
Date: Sun, 24 May 2009 12:34:29 -0400

Hi Jorge, Christian,

Jorge makes some decent points and I also verified that his use of
AttributeError (instantiating it with a key string) does result in
slightly more useful output. I've pushed this change as commit
f282856. Thanks Jorge!

Best,
Jeff

On Thu, May 21, 2009 at 9:02 AM, Jorge Vargas <address@hidden> wrote:
> 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.
>>
>
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/fab-user
>




reply via email to

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