Skip to content

Why MagicFilter in aiogram doesn't have "__contains__", but have "in_"? #1476

Answered by JrooTJunior
aminabbasov asked this question in Q&A
Discussion options

You must be logged in to vote

Because in operator calls __contains__ on the right operand inplace and returns always boolean value and the magic filter, on the contrary, works in a delayed manner when necessary (on imcoming events).

So when you execute the following:

F.content_type in {ContentType.PHOTO, ContentType.VIDEO}

The presence of the filter object (F.content_type == delayed getattr) in the sequence shown on the right will be checked immediately.

and when you execute

F.content_type.in_({ContentType.PHOTO, ContentType.VIDEO})

the contains operation will be added to the filter and when resolve method the presence of the value of the specified attribute will be checked.


The same as in the SQLAlchemy ColumnClause…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aminabbasov
Comment options

Answer selected by aminabbasov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants