Skip to content

Commit 3ea14c9

Browse files
committed
45 | Remove redundant typing imports
1 parent eadb584 commit 3ea14c9

20 files changed

+202
-208
lines changed

docs/source/guides/create_own_components.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Example implementation
3131

3232
.. code-block:: python
3333
34-
from typing import Any, Dict
34+
from typing import Any
3535
3636
from flask_inputfilter.Condition import BaseCondition
3737
@@ -45,7 +45,7 @@ Example implementation
4545
self.first_field = first_field
4646
self.second_field = second_field
4747
48-
def check(self, data: Dict[str, Any]) -> bool:
48+
def check(self, data: dict[str, Any]) -> bool:
4949
return data.get(self.first_field) == data.get(self.second_field)
5050
5151
@@ -69,7 +69,7 @@ Example implementation
6969
.. code-block:: python
7070
7171
from datetime import date, datetime
72-
from typing import Any, Union
72+
from typing import Any
7373
7474
from flask_inputfilter.Filter import BaseFilter
7575
@@ -80,7 +80,7 @@ Example implementation
8080
Supports ISO 8601 formatted strings.
8181
"""
8282
83-
def apply(self, value: Any) -> Union[datetime, Any]:
83+
def apply(self, value: Any) -> datetime|Any:
8484
if isinstance(value, datetime):
8585
return value
8686
@@ -94,8 +94,7 @@ Example implementation
9494
except ValueError:
9595
return value
9696
97-
else:
98-
return value
97+
return value
9998
10099
101100
Validator
@@ -116,7 +115,7 @@ Example implementation
116115

117116
.. code-block:: python
118117
119-
from typing import Any, List, Optional
118+
from typing import Any, Optional
120119
121120
from flask_inputfilter.Exception import ValidationError
122121
from flask_inputfilter.Validator import BaseValidator
@@ -129,7 +128,7 @@ Example implementation
129128
130129
def __init__(
131130
self,
132-
haystack: List[Any],
131+
haystack: list[Any],
133132
strict: bool = False,
134133
error_message: Optional[str] = None,
135134
) -> None:

env_configs/cython.Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ FROM python:3.7-slim
22

33
WORKDIR /app
44

5-
RUN apt-get update && apt-get install -y g++ git
5+
RUN apt-get update \
6+
&& apt-get install -y g++ git \
7+
&& apt-get clean
68

79
COPY pyproject.toml /app
810

env_configs/env.Dockerfile

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@ FROM debian:buster-slim
22

33
WORKDIR /app
44

5-
RUN apt-get update && apt-get install -y \
6-
build-essential \
7-
curl \
8-
g++ \
9-
git \
10-
libbz2-dev \
11-
libffi-dev \
12-
libjpeg-dev \
13-
liblzma-dev \
14-
libncurses5-dev \
15-
libncursesw5-dev \
16-
libreadline-dev \
17-
libsqlite3-dev \
18-
libssl-dev \
19-
llvm \
20-
make \
21-
python3-dev \
22-
tk-dev \
23-
wget \
24-
xz-utils \
25-
zlib1g-dev
5+
RUN apt-get update \
6+
&& apt-get install -y \
7+
build-essential \
8+
curl \
9+
g++ \
10+
git \
11+
libbz2-dev \
12+
libffi-dev \
13+
libjpeg-dev \
14+
liblzma-dev \
15+
libncurses5-dev \
16+
libncursesw5-dev \
17+
libreadline-dev \
18+
libsqlite3-dev \
19+
libssl-dev \
20+
llvm \
21+
make \
22+
python3-dev \
23+
tk-dev \
24+
wget \
25+
xz-utils \
26+
zlib1g-dev \
27+
&& apt-get clean
2628

2729
RUN curl https://pyenv.run | bash
2830

2931
ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:/root/.pyenv/versions/3.7.12/bin:$PATH"
30-
RUN echo 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc
31-
RUN echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
32-
RUN echo 'eval "$(pyenv init -)"' >> ~/.bashrc
33-
RUN echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
32+
RUN echo 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc \
33+
&& echo 'eval "$(pyenv init --path)"' >> ~/.bashrc \
34+
&& echo 'eval "$(pyenv init -)"' >> ~/.bashrc \
35+
&& echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
3436

3537
RUN /root/.pyenv/bin/pyenv install 3.7.12
3638
RUN /root/.pyenv/bin/pyenv install 3.8.12

env_configs/pure.Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ FROM python:3.7-slim
22

33
WORKDIR /app
44

5-
RUN apt-get update && apt-get install -y git
5+
RUN apt-get update \
6+
&& apt-get install -y git \
7+
&& apt-get clean
68

79
COPY pyproject.toml /app
810

flask_inputfilter/Condition/CustomCondition.py

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

3-
from typing import Any, Callable, Dict
3+
from collections.abc import Callable
4+
from typing import Any, Dict
45

56
from flask_inputfilter.Condition import BaseCondition
67

flask_inputfilter/Filter/Base64ImageDownscaleFilter.py

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

33
import base64
4-
import binascii
54
import io
65
from typing import Any, Optional
76

8-
from PIL import Image, UnidentifiedImageError
7+
from PIL import Image
98

109
from flask_inputfilter.Filter import BaseFilter
1110

@@ -39,13 +38,7 @@ def apply(self, value: Any) -> Any:
3938
image = Image.open(io.BytesIO(base64.b64decode(value)))
4039
return self.resize_picture(image)
4140

42-
except (
43-
binascii.Error,
44-
UnidentifiedImageError,
45-
OSError,
46-
ValueError,
47-
TypeError,
48-
):
41+
except (OSError, ValueError, TypeError):
4942
return value
5043

5144
def resize_picture(self, image: Image) -> str:

flask_inputfilter/Filter/Base64ImageResizeFilter.py

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

33
import base64
4-
import binascii
54
import io
65
from typing import Any
76

8-
from PIL import Image, UnidentifiedImageError
7+
from PIL import Image
98

109
from flask_inputfilter.Enum import ImageFormatEnum
1110
from flask_inputfilter.Filter import BaseFilter
@@ -46,13 +45,7 @@ def apply(self, value: Any) -> Any:
4645

4746
value = Image.open(io.BytesIO(base64.b64decode(value)))
4847
return self.reduce_image(value)
49-
except (
50-
binascii.Error,
51-
UnidentifiedImageError,
52-
OSError,
53-
ValueError,
54-
TypeError,
55-
):
48+
except (OSError, ValueError, TypeError):
5649
return value
5750

5851
def reduce_image(self, image: Image) -> Image:

flask_inputfilter/Filter/ToEnumFilter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ def __init__(self, enum_class: Type[Enum]) -> None:
1717
self.enum_class = enum_class
1818

1919
def apply(self, value: Any) -> Union[Enum, Any]:
20-
if not isinstance(value, (str, int)):
21-
return value
22-
23-
elif isinstance(value, Enum):
20+
if not isinstance(value, (str, int)) or isinstance(value, Enum):
2421
return value
2522

2623
try:

flask_inputfilter/Filter/ToIsoFilter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ class ToIsoFilter(BaseFilter):
1212
"""
1313

1414
def apply(self, value: Any) -> Union[str, Any]:
15-
if isinstance(value, datetime):
16-
return value.isoformat()
17-
18-
elif isinstance(value, date):
15+
if isinstance(value, (datetime, date)):
1916
return value.isoformat()
2017

2118
return value

0 commit comments

Comments
 (0)