← index #7639Issue #679
Related · high · value 2.768
QUERY · ISSUE

micropython dict has not __contains__ method

openby bhcuong2008opened 2021-08-11updated 2021-08-12
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

problems with __contains__ magic method

closedby kimbautersopened 2014-06-10updated 2014-06-11

The magic method __contains__ seems to be defined in the micropython code, but it doesn't work. I have been trying to hunt down the problem and have failed to pinpoint it so far. The bug is easily reproducible:

class problem:
    def __contains__(self, key):
        return True

test = problem()
if True in test:
    print("__contains__ works")

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied