Why MagicFilter in aiogram doesn't have "__contains__", but have "in_"? #1476
-
In my opinion, having the option to check the presence of My view: F.content_type in {ContentType.PHOTO, ContentType.VIDEO} Current: F.content_type.in_({ContentType.PHOTO, ContentType.VIDEO}) But I think this is quite an obvious idea to implement |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Because So when you execute the following: F.content_type in {ContentType.PHOTO, ContentType.VIDEO} The presence of the filter object ( and when you execute F.content_type.in_({ContentType.PHOTO, ContentType.VIDEO}) the The same as in the SQLAlchemy |
Beta Was this translation helpful? Give feedback.
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:
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
the
contains
operation will be added to the filter and whenresolve
method the presence of the value of the specified attribute will be checked.The same as in the SQLAlchemy
ColumnClause…