Skip to content

[FEATURE] Switch filters to kwarg in MessageHandler #3394

@Viicos

Description

@Viicos

What kind of feature are you missing? Where do you notice a shortcoming of PTB?

The filters argument of the MessageHandler constructor is currently a positional argument and defaults to filters.ALL if None is explicitly passed:

def __init__(
self,
filters: filters_module.BaseFilter,
callback: HandlerCallback[Update, CCT, RT],
block: DVInput[bool] = DEFAULT_TRUE,
):
super().__init__(callback, block=block)
self.filters = filters if filters is not None else filters_module.ALL

Describe the solution you'd like

Using a keyword argument instead:

 def __init__( 
     self,
     callback: HandlerCallback[Update, CCT, RT],
     filters: filters_module.BaseFilter = filters.ALL,
     block: DVInput[bool] = DEFAULT_TRUE,
 ): 
  
     super().__init__(callback, block=block) 
     self.filters = filters

Or something similar.

Documentation could be improved as well:

operators (& for and, | for or, ~ for not). This defaults to all message updates
being: :attr:`telegram.Update.message`, :attr:`telegram.Update.edited_message`,
:attr:`telegram.Update.channel_post` and :attr:`telegram.Update.edited_channel_post`.
If you don't want or need any of those pass ``~filters.UpdateType.*`` in the filter
argument.

Seems unclear to me when it is stating pass ``~filters.UpdateType.*`` in the filter argument.

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions