__init__ method for containers

Calvin Spealman ironfroggy at socialserve.com
Wed Dec 12 11:41:24 EST 2007


On Dec 12, 2007, at 4:05 PM, Neil Cerutti wrote:

> On 2007-12-12, Calvin Spealman <ironfroggy at socialserve.com> wrote:
>> I agree that the behavior should be more consistant, but you
>> also  should not be calling __init__ more than once on any
>> given instance  and that in and of itself should probably
>> constitute undefined behavior.
>
> That seems wise to me, too, but the the explicit __init__ test in
> test_deque seems to argue otherwise. Maybe the test in error.
>
> Moreover, the behavior of deque.__init__ may actually contradict
> its doc string.

It documents that deque.__init__ initializes it, as all __init__  
methods do. All init methods are also assumed to _only_ be called at  
the start of the life of the object and never more than once, so  
breaking that breaks assumption and thus the documentation isn't  
wrong because you are trying to apply it to a state that shouldn't  
exist. This like saying saying claims of cigarettes causing cancer  
are false if you shoot someone before they get the cancer. Well, you  
aren't supposed to shoot people, so that doesn't count.

>>>> help(deque.__init__)
> Help on wrapper_descriptor:
>
> __init__(...)
>     x.__init__(...) initializes x; see x.__class__.__doc__ for  
> signature
>
> -- 
> Neil Cerutti
> A song fest was hell at the Methodist church Wednesday. --Church  
> Bulletin
> Blooper
> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list