QUERY · ISSUE
micropython dict has not __contains__ method
py-core
Hi Team,
Today I check contains method of dict, but not found. MicroPython v1.16. I open file objdict.c, and also not found. Is it missed?
Thanks,
Cuong.
CANDIDATE · ISSUE
CPython difference for __contains__ method
py-core
class TestContains:
def __contains__(self, arg):
return arg
print(0 in TestContains())
print(1 in TestContains())
print('' in TestContains())
print(0 not in TestContains())
print(1 not in TestContains())
print('' not in TestContains())
CPython:
False
True
False
True
False
True
because https://docs.python.org/3/reference/expressions.html#membership-test-operations
For user-defined classes which define the contains() method, x in y returns True if y.contains(x) returns a true value, and False otherwise.
MicroPython:
0
1
True
False
True
Unexpected results so definitely worthy of a cpydiff addition, or should this be fixed?