-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Make filters and/or-able using bitwise operators. #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
See associated PR for more info.
__call__ is scary looking for users wanted to create their own filters. Also allows us to put additional logic in __call__ if we want in the future.
# Conflicts: # telegram/ext/messagehandler.py # tests/test_filters.py
Also add tests with both & and |.
Also deprecates actually using a list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nitpic documentation changes, otherwise LGTM 👍
|
||
And: | ||
|
||
>>> (Filters.text & Filters.entity(MENTION) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed a )
here
|
||
Also works with more than two filters: | ||
|
||
>>> (Filters.text & (Filters.entity(URL |Filters.entity(TEXT_LINK)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also looks wrong to me
class MergedFilter(BaseFilter): | ||
"""Represents a filter consisting of two other filters.""" | ||
|
||
def __init__(self, base_filter, and_filter=None, or_filter=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring indicating that and_filter
and or_filter
are mutually exclusive
Since and empty list cannot (in the future, currently only deprecated) be used.
Would allow filters to be and'ed/or'ed.
Using syntax like this:
Currently this isn't too useful since the only filter that can be and'ed to any other is
forwarded
, but that should all change with #409.The code currently requires all filters to be created as a class and then initiated before they can be used, which could be an inconvenience to the user if they want to create their own filters. To remedy this we could add a decorator like this:
That would allow users (and us) to make filters like this:
The reason I didn't immediately go with this, is that it might be confusing if someone (especially someone new to python) reading the code stumbles upon a dynamic class creator.
Thoughts?
Edit: After talking in dev group, the decorator has been declared too gross to look at :P