I have a class which .defines the __getitem__, __setitem__ methods (and keys and items as well), and behaves like a dictionary, where keys are strings.
However, the in operator does not behave as expected:
>>> myObject=MyClass()
>>> 'abc' in myObject.keys()
False
>>> 'abc' in myObject
ArgumentError: Python argument types in
MyClass.__getitem__(MyClass, int)
did not match the C++ signature:
__getitem__(MyClass {lvalue}, std::string)
Why is python trying to call __getitem__ with int, when I use the str key?
It seems that
is being evaluated as:
Where
iis an integer.Try implementing the
__contains__(self, value)magic method.