-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Refactor Filters #2178
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
Comments
Following up on this, I was thinking about why we have the python-telegram-bot/telegram/ext/messagehandler.py Lines 26 to 30 in 2c2aaea
Regarding the namespace, I see no notable added benefit of grouping the filters in a
to
(A nice side effect of this would be probably behave better) More importantly, we have by now made a full transition to class-based filters, where we have three different cases:
Because we use
Case 3 is a bit more tricky and I see different options: 1. As close to the current situation as possibleSticking to the 2. The hacky solutionWe can add a 3. KISSAdd Personally, I'm somewhat in favor of the KISS-solution, as IMO it offers the cleanest API to the user. |
Another comment: currently in |
Hi, can I have a go at this? |
Hi. IIRC we haven't made a final decision on this, which is why I didn't tag it for hacktoberfest. If @Poolitzer @starry69 @harshil21 are on board with the |
KISS FTW. If applied consistently throughout |
Oh I see... Thanks for the info! |
I like the KISS + shortcut solution |
@jeffsieu with Pool and harshil agreeing to the KISS solution, we can go ahead with this. If you would like to PR for this, please leave a short comment here so that I can assign you :) |
Another refactoring idea: I was thinking about the nested filters, e.g. For However, |
Currently filters check updates via the
__call__
method. When switching from function-based filters to class-based filters, this was mainly done to maintain backwards compatibility withfilter(update)
. However with some of the new filters functionalities, this leads to ugly workarounds likepython-telegram-bot/telegram/ext/filters.py
Lines 329 to 350 in 8e7c0d6
I therefore propose to refactor to something along the lines of
This matches the
Handler.check_update
interface and allows for filters having a custom__init__
, wich can still be called through instances of those filters.However, this is somewhat breaking: While
BaseFilter.__call__
is undocumented, people might still haveFilters.existing_filter(update)
somewhere within their custom filters. So maybe this is better suited for a major release.The text was updated successfully, but these errors were encountered: