diff --git a/CHANGES/667.misc b/CHANGES/667.misc new file mode 100644 index 00000000..22fc86e9 --- /dev/null +++ b/CHANGES/667.misc @@ -0,0 +1 @@ +Disable ContentType filter by default diff --git a/aiogram/dispatcher/filters/content_types.py b/aiogram/dispatcher/filters/content_types.py index 177ecdae..dc96ca23 100644 --- a/aiogram/dispatcher/filters/content_types.py +++ b/aiogram/dispatcher/filters/content_types.py @@ -11,10 +11,9 @@ from .base import BaseFilter class ContentTypesFilter(BaseFilter): """ Is useful for handling specific types of messages (For example separate text and stickers handlers). - This is always automatically adds to the filters list for message handlers. """ - content_types: Optional[Union[Sequence[str], str]] = None + content_types: Union[Sequence[str], str] """Sequence of allowed content types""" @validator("content_types") @@ -32,7 +31,4 @@ class ContentTypesFilter(BaseFilter): return value async def __call__(self, message: Message) -> Union[bool, Dict[str, Any]]: - if not self.content_types: # pragma: no cover - # Is impossible but needed for valid typechecking - self.content_types = [ContentType.TEXT] return ContentType.ANY in self.content_types or message.content_type in self.content_types diff --git a/tests/test_dispatcher/test_filters/test_content_types.py b/tests/test_dispatcher/test_filters/test_content_types.py index 8d1706b2..046073c4 100644 --- a/tests/test_dispatcher/test_filters/test_content_types.py +++ b/tests/test_dispatcher/test_filters/test_content_types.py @@ -16,12 +16,6 @@ class MinimalMessage: class TestContentTypesFilter: - async def test_validator_empty(self): - filter_ = ContentTypesFilter() - assert not filter_.content_types - await filter_(cast(Message, MinimalMessage(ContentType.TEXT))) - assert filter_.content_types == [ContentType.TEXT] - def test_validator_empty_list(self): filter_ = ContentTypesFilter(content_types=[]) assert filter_.content_types == [] @@ -46,7 +40,6 @@ class TestContentTypesFilter: @pytest.mark.parametrize( "values,content_type,result", [ - [[], ContentType.TEXT, True], [[ContentType.TEXT], ContentType.TEXT, True], [[ContentType.PHOTO], ContentType.TEXT, False], [[ContentType.ANY], ContentType.TEXT, True],