Skip to content

Commit cb4241c

Browse files
authored
Merge pull request #62 from LeanderCS/enforce-typing-with-ruff
Add more ruff rules, to enforce typing
2 parents cff70ce + dd13abb commit cb4241c

File tree

12 files changed

+61
-13
lines changed

12 files changed

+61
-13
lines changed

docs/source/changelog.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ Changelog
33

44
All notable changes to this project will be documented in this file.
55

6+
[0.6.3] - 2025-09-24
7+
--------------------
8+
9+
Added
10+
^^^^^
11+
- Added default timeout of 30s for external api requests.
12+
13+
Changed
14+
^^^^^^^
15+
- Switched to more strict exception types for image filter.
16+
17+
618
[0.6.2] - 2025-07-03
719
--------------------
820

flask_inputfilter/filters/to_base64_image_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def apply(self, value: Any) -> Any:
7070
try:
7171
Image.open(io.BytesIO(base64.b64decode(value))).verify()
7272
return value
73-
except Exception:
73+
except (ValueError, OSError, base64.binascii.Error):
7474
pass
7575

7676
# Try to open as raw bytes

flask_inputfilter/filters/to_image_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def apply(self, value: Any) -> Any:
5151
# Try to decode as base64
5252
try:
5353
return Image.open(io.BytesIO(base64.b64decode(value)))
54-
except Exception:
54+
except (ValueError, OSError, base64.binascii.Error):
5555
pass
5656

5757
# Try to open as raw bytes

flask_inputfilter/filters/to_typed_dict_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any
3+
from typing import Any, Type
44

55
from flask_inputfilter.models import BaseFilter
66

@@ -34,7 +34,7 @@ def __init__(self):
3434

3535
__slots__ = ("typed_dict",)
3636

37-
def __init__(self, typed_dict) -> None:
37+
def __init__(self, typed_dict: Type) -> None:
3838
"""
3939
Parameters:
4040
typed_dict (Type[TypedDict]): The TypedDict class

flask_inputfilter/input_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def decorator(
104104
"""
105105

106106
def wrapper(
107-
*args, **kwargs
107+
*args: Any, **kwargs: Any
108108
) -> Union[Response, tuple[Any, dict[str, Any]]]:
109109
"""
110110
Wrapper function to handle input validation and error handling

flask_inputfilter/mixins/external_api_mixin/_external_api_mixin.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ cdef class ExternalApiMixin:
7979
requestData["method"] = config.method
8080

8181
try:
82-
response = requests.request(**requestData)
82+
response = requests.request(timeout=30, **requestData)
8383
result = response.json()
8484
except requests.exceptions.RequestException:
8585
if fallback is None:

flask_inputfilter/mixins/external_api_mixin/external_api_mixin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def call_external_api(
8383
request_data["method"] = config.method
8484

8585
try:
86-
response = requests.request(**request_data)
86+
response = requests.request(timeout=30, **request_data)
8787
result = response.json()
8888
except requests.exceptions.RequestException:
8989
if fallback is None:

flask_inputfilter/validators/is_dataclass_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __init__(
113113
)
114114
)
115115

116-
def _format_error(self, error_type: str, **kwargs) -> str:
116+
def _format_error(self, error_type: str, **kwargs: Any) -> str:
117117
"""Format error message using template or custom message."""
118118
if self.error_message:
119119
return self.error_message

flask_inputfilter/validators/is_horizontal_image_validator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import base64
44
import binascii
55
import io
6+
from typing import Any, Optional
67

78
from PIL import Image
89
from PIL.Image import Image as ImageType
@@ -41,10 +42,10 @@ def __init__(self):
4142

4243
__slots__ = ("error_message",)
4344

44-
def __init__(self, error_message=None):
45+
def __init__(self, error_message: Optional[str] = None) -> None:
4546
self.error_message = error_message
4647

47-
def validate(self, value):
48+
def validate(self, value: Any) -> None:
4849
if not isinstance(value, (str, ImageType)):
4950
raise ValidationError(
5051
"The value is not an image or its base 64 representation."

flask_inputfilter/validators/is_vertical_image_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self):
4242

4343
__slots__ = ("error_message",)
4444

45-
def __init__(self, error_message: Optional[str] = None):
45+
def __init__(self, error_message: Optional[str] = None) -> None:
4646
self.error_message = (
4747
error_message or "The image is not vertically oriented."
4848
)

0 commit comments

Comments
 (0)