Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit d6c8f29

Browse files
committed
Added missing types
1 parent b7604d4 commit d6c8f29

17 files changed

+116
-12
lines changed

flask_utils/decorators.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ def validate_params(
217217
218218
:param parameters: Dictionary of parameters to validate. The keys are parameter names
219219
and the values are the expected types.
220+
:type parameters: Dict[Any, Any]
220221
:param allow_empty: Allow empty values for parameters. Defaults to False.
222+
:type allow_empty: bool
221223
222224
:raises BadRequestError: If the JSON body is malformed,
223225
the Content-Type header is missing or incorrect, required parameters are missing,

flask_utils/errors/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ def _register_error_handlers(application: Flask) -> None:
2020
This function will register all the error handlers for the application
2121
2222
:param application: The Flask application to register the error handlers
23+
:type application: flask.Flask
24+
2325
:return: None
26+
:rtype: None
2427
2528
.. versionchanged:: 0.5.0
2629
Made the function private. If you want to register the custom error handlers, you need to
@@ -50,7 +53,10 @@ def generate_badrequest(error: BadRequestError) -> Response:
5053
a custom message and the 400 code
5154
5255
:param error: The error body
56+
:type error: BadRequestError
57+
5358
:return: Returns the response formatted
59+
:rtype: flask.Response
5460
"""
5561
return _generate_error_json(error, 400)
5662

@@ -61,7 +67,10 @@ def generate_conflict(error: ConflictError) -> Response:
6167
a custom message and the 409 code
6268
6369
:param error: The error body
70+
:type error: ConflictError
71+
6472
:return: Returns the response formatted
73+
:rtype: flask.Response
6574
"""
6675

6776
return _generate_error_json(error, 409)
@@ -73,7 +82,10 @@ def generate_forbidden(error: ForbiddenError) -> Response:
7382
a custom message and the 403 code
7483
7584
:param error: The error body
85+
:type error: ForbiddenError
86+
7687
:return: Returns the response formatted
88+
:rtype: flask.Response
7789
"""
7890

7991
return _generate_error_json(error, 403)
@@ -85,7 +97,10 @@ def generate_notfound(error: NotFoundError) -> Response:
8597
a custom message and the 404 code.
8698
8799
:param error: The error body
100+
:type error: NotFoundError
101+
88102
:return: Returns the response formatted
103+
:rtype: flask.Response
89104
"""
90105

91106
return _generate_error_json(error, 404)
@@ -97,7 +112,10 @@ def generate_unauthorized(error: UnauthorizedError) -> Response:
97112
a custom message and the 401 code.
98113
99114
:param error: The error body
115+
:type error: UnauthorizedError
116+
100117
:return: Returns the response formatted
118+
:rtype: flask.Response
101119
"""
102120

103121
return _generate_error_json(error, 401)
@@ -109,7 +127,10 @@ def generate_origin_is_unreachable(error: OriginIsUnreachableError) -> Response:
109127
a custom message and the 523 code.
110128
111129
:param error: The error body
130+
:type error: OriginIsUnreachableError
131+
112132
:return: Returns the response formatted
133+
:rtype: flask.Response
113134
"""
114135

115136
return _generate_error_json(error, 523)
@@ -121,7 +142,10 @@ def generate_web_server_is_down(error: WebServerIsDownError) -> Response:
121142
a custom message and the 521 code.
122143
123144
:param error: The error body
145+
:type error: WebServerIsDownError
146+
124147
:return: Returns the response formatted
148+
:rtype: flask.Response
125149
"""
126150

127151
return _generate_error_json(error, 521)
@@ -133,7 +157,10 @@ def generate_failed_dependency(error: FailedDependencyError) -> Response:
133157
a custom message and the 424 code.
134158
135159
:param error: The error body
160+
:type error: FailedDependencyError
161+
136162
:return: Returns the response formatted
163+
:rtype: flask.Response
137164
"""
138165

139166
return _generate_error_json(error, 424)
@@ -145,7 +172,10 @@ def generate_gone(error: GoneError) -> Response:
145172
a custom message and the 410 code.
146173
147174
:param error: The error body
175+
:type error: GoneError
176+
148177
:return: Returns the response formatted
178+
:rtype: flask.Response
149179
"""
150180

151181
return _generate_error_json(error, 410)
@@ -157,7 +187,10 @@ def generate_unprocessable_entity(error: UnprocessableEntityError) -> Response:
157187
a custom message and the 422 code.
158188
159189
:param error: The error body
190+
:type error: UnprocessableEntityError
191+
160192
:return: Returns the response formatted
193+
:rtype: flask.Response
161194
"""
162195

163196
return _generate_error_json(error, 422)
@@ -169,7 +202,10 @@ def generate_service_unavailable(error: ServiceUnavailableError) -> Response:
169202
a custom message and the 503 code.
170203
171204
:param error: The error body
205+
:type error: ServiceUnavailableError
206+
172207
:return: Returns the response formatted
208+
:rtype: flask.Response
173209
"""
174210

175211
return _generate_error_json(error, 503)

flask_utils/errors/_error_template.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ def _generate_error_json(error: _BaseFlaskException, status_code: int) -> Respon
99
This function is used to generate a json of the error passed
1010
1111
:param error: The error containing the message and solution
12+
:type error: _BaseFlaskException
13+
1214
:param status_code: The status code of the error.
15+
:type status_code: int
16+
1317
:return: Returns a json containing all the info
18+
:rtype: flask.Response
1419
1520
:Example:
1621

flask_utils/errors/badrequest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class BadRequestError(_BaseFlaskException):
1111
:param msg: The message to be displayed in the error.
1212
:type msg: str
1313
:param solution: The solution to the error.
14-
:type solution: str
14+
:type solution: Optional[str]
1515
1616
:Example:
1717

flask_utils/errors/base_class.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33

44
class _BaseFlaskException(Exception):
5+
"""
6+
This is the base class for all the exceptions in this package.
7+
8+
:param msg: The message to be displayed in the error.
9+
:type msg: str
10+
:param solution: The solution to the error.
11+
:type solution: Optional[str]
12+
:param status_code: The status code of the error.
13+
:type status_code: Optional[int]
14+
:param name: The name of the error.
15+
:type name: Optional[str]
16+
17+
:Example:
18+
19+
.. code-block:: python
20+
21+
from flask_utils.errors import _BaseFlaskException
22+
23+
class MyError(_BaseFlaskException):
24+
self.name = "MyError"
25+
self.msg = msg
26+
self.solution = solution
27+
self.status_code = 666
28+
29+
.. versionadded:: 0.1.0
30+
"""
31+
532
name: Optional[str] = None
633
msg: Optional[str] = None
734
solution: Optional[str] = "Try again."
35+
status_code: Optional[int] = 400

flask_utils/errors/conflict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ConflictError(_BaseFlaskException):
1111
:param msg: The message to be displayed in the error.
1212
:type msg: str
1313
:param solution: The solution to the error.
14-
:type solution: str
14+
:type solution: Optional[str]
1515
1616
:Example:
1717

flask_utils/errors/failed_dependency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FailedDependencyError(_BaseFlaskException):
1111
:param msg: The message to be displayed in the error.
1212
:type msg: str
1313
:param solution: The solution to the error.
14-
:type solution: str
14+
:type solution: Optional[str]
1515
1616
:Example:
1717

flask_utils/errors/forbidden.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ForbiddenError(_BaseFlaskException):
1111
:param msg: The message to be displayed in the error.
1212
:type msg: str
1313
:param solution: The solution to the error.
14-
:type solution: str
14+
:type solution: Optional[str]
1515
1616
:Example:
1717

flask_utils/errors/gone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class GoneError(_BaseFlaskException):
1111
:param msg: The message to be displayed in the error.
1212
:type msg: str
1313
:param solution: The solution to the error.
14-
:type solution: str
14+
:type solution: Optional[str]
1515
1616
:Example:
1717

flask_utils/errors/notfound.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class NotFoundError(_BaseFlaskException):
1111
:param msg: The message to be displayed in the error.
1212
:type msg: str
1313
:param solution: The solution to the error.
14-
:type solution: str
14+
:type solution: Optional[str]
1515
1616
:Example:
1717

0 commit comments

Comments
 (0)