Skip to content

Commit dbeabaa

Browse files
committed
Update diverse things
1 parent 9e13980 commit dbeabaa

38 files changed

+1585
-64
lines changed

flask_inputfilter/conditions/integer_bigger_than_condition.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import Any
4+
35
from flask_inputfilter.models import BaseCondition
46

57

@@ -45,7 +47,7 @@ def __init__(self, bigger_field: str, smaller_field: str) -> None:
4547
self.bigger_field = bigger_field
4648
self.smaller_field = smaller_field
4749

48-
def check(self, data: dict[str, int]) -> bool:
50+
def check(self, data: dict[str, Any]) -> bool:
4951
if (
5052
data.get(self.bigger_field) is None
5153
or data.get(self.smaller_field) is None

flask_inputfilter/conditions/n_of_condition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, fields: list[str], n: int) -> None:
4545
self.fields = fields
4646
self.n = n
4747

48-
def check(self, data: Any) -> bool:
48+
def check(self, data: dict[str, Any]) -> bool:
4949
return (
5050
sum(1 for field in self.fields if data.get(field) is not None)
5151
>= self.n

flask_inputfilter/conditions/string_longer_than_condition.py

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

3+
from typing import Any
4+
35
from flask_inputfilter.models import BaseCondition
46

57

@@ -40,7 +42,7 @@ def __init__(self, longer_field: str, shorter_field: str) -> None:
4042
self.longer_field = longer_field
4143
self.shorter_field = shorter_field
4244

43-
def check(self, value: dict[str, str]) -> bool:
44-
return len(value.get(self.longer_field) or 0) > len(
45-
value.get(self.shorter_field) or 0
45+
def check(self, data: dict[str, Any]) -> bool:
46+
return len(data.get(self.longer_field) or "") > len(
47+
data.get(self.shorter_field) or ""
4648
)

flask_inputfilter/declarative/_utils.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ def register_class_attribute(attribute_name: str, value: Any) -> None:
1616
attribute_name: The name of the attribute to set on the class
1717
value: The value to set for the attribute
1818
"""
19-
frame = inspect.currentframe()
20-
if frame and frame.f_back and frame.f_back.f_back:
21-
caller_locals = frame.f_back.f_back.f_locals
22-
if "__module__" in caller_locals and "__qualname__" in caller_locals:
23-
caller_locals[attribute_name] = value
19+
try:
20+
frame = inspect.currentframe()
21+
if frame and frame.f_back and frame.f_back.f_back:
22+
caller_locals = frame.f_back.f_back.f_locals
23+
if (
24+
"__module__" in caller_locals
25+
and "__qualname__" in caller_locals
26+
):
27+
caller_locals[attribute_name] = value
28+
except (AttributeError, KeyError):
29+
pass
2430

2531

2632
def append_to_class_list(list_name: str, value: Any) -> None:
@@ -36,10 +42,16 @@ def append_to_class_list(list_name: str, value: Any) -> None:
3642
list_name: The name of the list attribute on the class
3743
value: The value to append to the list
3844
"""
39-
frame = inspect.currentframe()
40-
if frame and frame.f_back and frame.f_back.f_back:
41-
caller_locals = frame.f_back.f_back.f_locals
42-
if "__module__" in caller_locals and "__qualname__" in caller_locals:
43-
if list_name not in caller_locals:
44-
caller_locals[list_name] = []
45-
caller_locals[list_name].append(value)
45+
try:
46+
frame = inspect.currentframe()
47+
if frame and frame.f_back and frame.f_back.f_back:
48+
caller_locals = frame.f_back.f_back.f_locals
49+
if (
50+
"__module__" in caller_locals
51+
and "__qualname__" in caller_locals
52+
):
53+
if list_name not in caller_locals:
54+
caller_locals[list_name] = []
55+
caller_locals[list_name].append(value)
56+
except (AttributeError, KeyError):
57+
pass

flask_inputfilter/filters/string_remove_emojis_filter.py

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

33
import re
4-
from typing import Any, Optional, Union
4+
from typing import Any, Union
55

66
from flask_inputfilter.models import BaseFilter
77

@@ -38,7 +38,7 @@ class CommentFilter(InputFilter):
3838

3939
__slots__ = ()
4040

41-
def apply(self, value: Any) -> Union[Optional[str], Any]:
41+
def apply(self, value: Any) -> Union[str, Any]:
4242
if not isinstance(value, str):
4343
return value
4444

flask_inputfilter/filters/string_slugify_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
import unicodedata
5-
from typing import Any, Optional, Union
5+
from typing import Any, Union
66

77
from flask_inputfilter.enums import UnicodeFormEnum
88
from flask_inputfilter.models import BaseFilter
@@ -29,7 +29,7 @@ class PostFilter(InputFilter):
2929

3030
__slots__ = ()
3131

32-
def apply(self, value: Any) -> Union[Optional[str], Any]:
32+
def apply(self, value: Any) -> Union[str, Any]:
3333
if not isinstance(value, str):
3434
return value
3535

flask_inputfilter/filters/to_alpha_numeric_filter.py

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

33
import re
4-
from typing import Any, Optional, Union
4+
from typing import Any, Union
55

66
from flask_inputfilter.models import BaseFilter
77

@@ -28,7 +28,7 @@ class CodeFilter(InputFilter):
2828

2929
__slots__ = ()
3030

31-
def apply(self, value: Any) -> Union[Optional[str], Any]:
31+
def apply(self, value: Any) -> Union[str, Any]:
3232
if not isinstance(value, str):
3333
return value
3434

flask_inputfilter/filters/to_boolean_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, Optional, Union
3+
from typing import Any, Union
44

55
from flask_inputfilter.models import BaseFilter
66

@@ -26,5 +26,5 @@ class ActiveFilter(InputFilter):
2626

2727
__slots__ = ()
2828

29-
def apply(self, value: Any) -> Union[Optional[bool], Any]:
29+
def apply(self, value: Any) -> Union[bool, Any]:
3030
return bool(value)

flask_inputfilter/filters/to_dataclass_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, Type, Union
3+
from typing import Any, Type
44

55
from flask_inputfilter.models import BaseFilter
66

@@ -36,7 +36,7 @@ class DataFilter(InputFilter):
3636
def __init__(self, dataclass_type: Type[dict]) -> None:
3737
self.dataclass_type = dataclass_type
3838

39-
def apply(self, value: Any) -> Union[Any]:
39+
def apply(self, value: Any) -> Any:
4040
if not isinstance(value, dict):
4141
return value
4242

flask_inputfilter/filters/to_pascal_case_filter.py

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

33
import re
4-
from typing import Any, Optional, Union
4+
from typing import Any, Union
55

66
from flask_inputfilter.models import BaseFilter
77

@@ -28,7 +28,7 @@ class ClassNameFilter(InputFilter):
2828

2929
__slots__ = ()
3030

31-
def apply(self, value: Any) -> Union[Optional[str], Any]:
31+
def apply(self, value: Any) -> Union[str, Any]:
3232
if not isinstance(value, str):
3333
return value
3434

0 commit comments

Comments
 (0)