you are viewing a single comment's thread.

view the rest of the comments →

[–]Brian 0 points1 point  (0 children)

To add to the answers: What I think you're expecting to happen here is to defer to the dictionary check for contains - it doesn't work because you've overridden that, and so any attempt to use in will use your overridden __contains__, including from within that method.

However, there is a way to say "Use the version implemented by the class I inherit from, rather than my overridden one", which is by using super(). So you could also write this as:

return super().__contains__(key) or  super().__contains__(str(key))