[IronPython] Potential issue with the 'in' construction?
Dino Viehland
dinov at exchange.microsoft.com
Thu Jan 18 17:51:01 CET 2007
This is a bug, thanks for reporting it. Ops.In() needs to check for IPythonContainer before checking for IDictionary to detect the overridden method. I've opened bug 7426 for this (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=7426).
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Sylvain Hellegouarch
Sent: Thursday, January 18, 2007 7:56 AM
To: Discussion of IronPython
Subject: [IronPython] Potential issue with the 'in' construction?
Hi folks,
Say I have the following class:
class Test(dict):
def __getitem__(self, key):
print "__gelitem__ called"
return dict.__getitem__(self, key.title())
def __setitem__(self, key, value):
print "__selitem__ called"
dict.__setitem__(self, key.title(), value)
def __delitem__(self, key):
print "__delitem__ called"
dict.__delitem__(self, key.title())
def __contains__(self, key):
print "__contains__ called"
return dict.__contains__(self, key.title())
def has_key(self, key):
print "has_key called"
return dict.__contains__(self, key.title())
Now say I have this code:
if __name__ == "__main__":
u = Test()
u['simple'] = 'text'
print u.keys()
print 'simple' in u
print u.__contains__('simple')
print u.has_key('simple')
print u['simple']
del u['simple']
I will get the following output:
__selitem__ called
['Simple']
False
__contains__ called
True
has_key called
True
__gelitem__ called
text
__delitem__ called
As you can see all the overridden methods were correctly called except
the __contains__ on 'in' construction.
The same test with CPython:
__selitem__ called
['Simple']
__contains__ called
True
__contains__ called
True
has_key called
True
__gelitem__ called
text
__delitem__ called
In that case everything is as I expected.
So could there be a problem on the way IP manages "in"?
This looks like a minor bug but prevent me from running CherryPy 3 which
uses the same type of Case Insensitive dict to handle easily HTTP headers.
Thoughts on a workaround or fix?
- Sylvain
_______________________________________________
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