It seems Python 3.9 changed the semantics of __contains__
.
A Token can be tested for equality with a string, in that case the Token's text is tested for equality with the string.
Likewise, a Context can be compared with a Lexicon, in which case the Context's lexicon is test for equality with the specified Lexicon.
This used to work for the in
operator of lists and tuples, "text" in context
or some_lexicon in context
used to work, because __eq__
was called on the items of the sequence. But starting with Python 3.9, it seems the in
operator calls __eq__
the other way around, not on the sequence's item, but on the item that's searched for in the sequence.
Although we could keep stuff like:
if token == "text":
do_something()
we can't use the in
operator anymore, as it calls "text".__eq__(token)
instead of token.__eq__(text)
.
This also has consequences for the query.__call__()
method, which currently depends on the pre 3.9 behaviour.