[Python-Dev] 'hasattr' is broken by design
Steve Holden
steve at holdenweb.com
Tue Aug 24 16:49:07 CEST 2010
On 8/24/2010 9:45 AM, Benjamin Peterson wrote:
> 2010/8/24 Hrvoje Niksic <hrvoje.niksic at avl.com>:
>> On 08/24/2010 02:31 PM, Benjamin Peterson wrote:
>>>
>>> 2010/8/24 Hrvoje Niksic<hrvoje.niksic at avl.com>:
>>>>
>>>> The __length_hint__ lookup expects either no exception or
>>>> AttributeError,
>>>> and will propagate others. I'm not sure if this is a bug. On the one
>>>> hand,
>>>> throwing anything except AttributeError from __getattr__ is bad style
>>>> (which
>>>> is why we fixed the bug by deriving our business exception from
>>>> AttributeError), but the __length_hint__ check is supposed to be an
>>>> internal
>>>> optimization completely invisible to the caller of list().
>>>
>>> __length_hint__ is internal and undocumented, so it can do whatever it
>>> wants.
>>
>> Of course, but that's beside the point. In this case __length_hint__ was
>> neither implemented in the class, nor were we aware of its existence, and
>> the code still broke (as in the example in previous mail). The point I'm
>> making is that:
>>
>> a) a "business" case of throwing anything other than AttributeError from
>> __getattr__ and friends is almost certainly a bug waiting to happen, and
>>
>> b) making the proposed change is bound to break real, production code.
>
> I agree with. This is why the change is not making its way into any
> maintenance release.
>
>
>
+1
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
DjangoCon US September 7-9, 2010 http://djangocon.us/
See Python Video! http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/
More information about the Python-Dev
mailing list