[IronPython] very strange dictionnary bug

Dino Viehland dinov at exchange.microsoft.com
Fri Aug 18 22:02:06 CEST 2006


Could something like this be happening?

x = {2:3, 4:5}
for a in x.keys():
    if a == 2:
        del x[2]
        x[3] = 'abc'
    assert x.has_key(a)


This is similar to:

x = {2:3, 4:5}
keys = x.keys()
del x[4]
x[7] = 23
for a in keys:
 print a

where both CPython and IronPython print 2 and 4 (there is a snapshot of keys saved after the call to x.keys() and any modifications that don't alter the size of the dictionary aren't caught).


IronPython prints
________________________________________
From: users-bounces at lists.ironpython.com On Behalf Of Stanislas Pinte
Sent: Friday, August 18, 2006 8:26 AM
To: Discussion of IronPython
Subject: Re: [IronPython] very strange dictionnary bug

Dino Viehland a écrit :
> I haven't seen anything like this before... But I have a couple of questions:  Are the keys always strings when it repros?  And is the dictionary always created using the {} syntax?

the keys are always strings, and the dict is instantiated only once,
with the {} syntax.

Thanks,

Stan.
>
> I ask because we have a lot of different dictionary implementations, or there could be a bug where we have different instances of some basic object that are hashing differently for some reason (although given the code below, that seems strange).
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Stanislas Pinte
> Sent: Friday, August 18, 2006 7:38 AM
> To: Discussion of IronPython
> Subject: Re: [IronPython] very strange dictionnary bug
>
> By the way, the environment in which the bug shows up is single-threaded, so I do not suspect any concurrent access problem.
>
> Stan.
>
> Stanislas Pinte a écrit :
>> Hello,
>>
>> We are just seeing a very strange bug in the following code:
>>
>> myDictionnary = {}
>> .
>> for key in myDictionnary.keys():
>>   assert myDictionnary.has_key(key) --> throw AssertionError
>>
>> this is fixed by the following change:
>>
>> for key, value in myDictionnary.iteritems():
>>   ...
>>
>> Ever seen this?
>>
>> Too bad I cannot reproduce this...a very simple test case like the one
>> below doesn't do the trick...
>>
>> thanks,
>>
>> Stan.
>>
>> [sim-ironpython]> ironpython/ipy.exe
>> IronPython 1.0.60816 on .NET 2.0.50727.42 Copyright (c) Microsoft
>> Corporation. All rights reserved.
>>>>> a = {"one": 1, "two": 2, "three": 3} a["one"]
>> 1
>>>>> a.pop("one")
>> 1
>>>>> a
>> {'two': 2, 'three': 3}
>>>>> a.keys()
>> ['two', 'three']
>>>>> for k in a.keys():
>> .     print k
>> .
>> two
>> three
>>
>
>
> --
> -----------------------------------------------------------------
>    Stanislas Pinte             e-mail: stan at ertmssolutions.com
>    ERTMS Solutions               http://www.ertmssolutions.com
>    Rue de l'Autonomie, 1             Tel:    + 322 - 522.06.63
>    1070        Bruxelles              Fax:   + 322 - 522.09.30
> -----------------------------------------------------------------
>    Skype (http://www.skype.com) id:                  stanpinte
> -----------------------------------------------------------------
>
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>


--
-----------------------------------------------------------------
   Stanislas Pinte             e-mail: stan at ertmssolutions.com
   ERTMS Solutions               http://www.ertmssolutions.com
   Rue de l'Autonomie, 1             Tel:    + 322 - 522.06.63
   1070        Bruxelles              Fax:   + 322 - 522.09.30
-----------------------------------------------------------------
   Skype (http://www.skype.com) id:                  stanpinte
-----------------------------------------------------------------

_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list