Skip to content

Commit e425b8c

Browse files
committed
Merge branch 'master' into dev/smt5541/typing_list_deprecated
2 parents ca8ab1b + 1db7e5a commit e425b8c

File tree

9 files changed

+884
-114
lines changed

9 files changed

+884
-114
lines changed

.github/pull_request_template.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### 🛠 Changes being made
2+
3+
#### Give examples of the changes you've made in this pull request. Include an itemized list if you can.
4+
5+
### 🧠 Rationale behind the change
6+
7+
#### Why did you choose to make these changes?
8+
9+
#### Does this pull request resolve any open issues?
10+
11+
#### Were there any trade-offs you had to consider?
12+
13+
### 🧪 Testing
14+
15+
- [ ] Have tests been added or updated for the changes introduced in this pull request?
16+
17+
- [ ] Are the changes backwards compatible?
18+
19+
#### If the changes aren't backwards compatible, what other options were explored?
20+
21+
### ✨ Quality check
22+
23+
- [ ] Are your changes free of any erroneous print statements, debuggers or other leftover code?
24+
25+
- [ ] Has the README been updated to reflect the changes introduced (if applicable)?
26+
27+
### 💬 Additional comments

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if __name__ == "__main__":
3838
## Usage
3939
To validate parameters with flask-parameter-validation, two conditions must be met.
4040
1. The `@ValidateParameters()` decorator must be applied to the function
41-
2. Type hints ([supported types](#type-hints-and-accepted-input-types)) and a default of a subclass of `Parameter` must be supplied per parameter flask-parameter-validation parameter
41+
2. Type hints ([supported types](#type-hints-and-accepted-input-types)) and a default of a subclass of `Parameter` must be supplied per parameter
4242

4343

4444
### Enable and customize Validation for a Route with the @ValidateParameters decorator
@@ -108,20 +108,20 @@ Note: "**POST Methods**" refers to the HTTP methods that send data in the reques
108108
#### Type Hints and Accepted Input Types
109109
Type Hints allow for inline specification of the input type of a parameter. Some types are only available to certain `Parameter` subclasses.
110110

111-
| Type Hint / Expected Python Type | Notes | `Route` | `Form` | `Json` | `Query` | `File` |
112-
|------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|---------|--------|--------|---------|--------|
113-
| `str` | | Y | Y | Y | Y | N |
114-
| `int` | | Y | Y | Y | Y | N |
115-
| `bool` | | Y | Y | Y | Y | N |
116-
| `float` | | Y | Y | Y | Y | N |
117-
|`list`/`typing.List` (`typing.List` is [deprecated](https://docs.python.org/3/library/typing.html#typing.List)) | For `Query` and `Form` inputs, users can pass via either `value=1&value=2&value=3`, or `value=1,2,3`, both will be transformed to a `list`. | N | Y | Y | Y | N |
118-
| `typing.Union` | Cannot be used inside of `typing.List` | Y | Y | Y | Y | N |
119-
| `typing.Optional` | | Y | Y | Y | Y | Y |
120-
| `datetime.datetime` | Received as a `str` in ISO-8601 date-time format | Y | Y | Y | Y | N |
121-
| `datetime.date` | Received as a `str` in ISO-8601 full-date format | Y | Y | Y | Y | N |
122-
| `datetime.time` | Received as a `str` in ISO-8601 partial-time format | Y | Y | Y | Y | N |
123-
| `dict` | For `Query` and `Form` inputs, users should pass the stringified JSON | N | Y | Y | Y | N |
124-
| `FileStorage` | | N | N | N | N | Y |
111+
| Type Hint / Expected Python Type | Notes | `Route` | `Form` | `Json` | `Query` | `File` |
112+
|------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|--------|--------|---------|--------|
113+
| `str` | | Y | Y | Y | Y | N |
114+
| `int` | | Y | Y | Y | Y | N |
115+
| `bool` | | Y | Y | Y | Y | N |
116+
| `float` | | Y | Y | Y | Y | N |
117+
| `list`/`typing.List` (`typing.List` is [deprecated](https://docs.python.org/3/library/typing.html#typing.List)) | For `Query` and `Form` inputs, users can pass via either `value=1&value=2&value=3`, or `value=1,2,3`, both will be transformed to a `list` | N | Y | Y | Y | N |
118+
| `typing.Union` | Cannot be used inside of `typing.List` | Y | Y | Y | Y | N |
119+
| `typing.Optional` | | Y | Y | Y | Y | Y |
120+
| `datetime.datetime` | Received as a `str` in ISO-8601 date-time format | Y | Y | Y | Y | N |
121+
| `datetime.date` | Received as a `str` in ISO-8601 full-date format | Y | Y | Y | Y | N |
122+
| `datetime.time` | Received as a `str` in ISO-8601 partial-time format | Y | Y | Y | Y | N |
123+
| `dict` | For `Query` and `Form` inputs, users should pass the stringified JSON | N | Y | Y | Y | N |
124+
| `FileStorage` | | N | N | N | N | Y |
125125

126126
These can be used in tandem to describe a parameter to validate: `parameter_name: type_hint = ParameterSubclass()`
127127
- `parameter_name`: The field name itself, such as username

flask_parameter_validation/parameter_types/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from .json import Json
44
from .query import Query
55
from .route import Route
6+
from .multi_source import MultiSource
67

78
__all__ = [
8-
"File", "Form", "Json", "Query", "Route"
9+
"File", "Form", "Json", "Query", "Route", "MultiSource"
910
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import Type
2+
3+
from flask_parameter_validation.parameter_types.parameter import Parameter
4+
5+
6+
class MultiSource(Parameter):
7+
name = "multi_source"
8+
9+
def __init__(self, *sources: list[Type[Parameter]], **kwargs):
10+
self.sources = [Source(**kwargs) for Source in sources]
11+
super().__init__(**kwargs)

flask_parameter_validation/parameter_types/parameter.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import re
66
from datetime import date, datetime, time
7+
78
import dateutil.parser as parser
89
import jsonschema
910
from jsonschema.exceptions import ValidationError as JSONSchemaValidationError
@@ -150,8 +151,6 @@ def validate(self, value):
150151
if self.func is not None and not original_value_type_list:
151152
self.func_helper(value)
152153

153-
154-
155154
return True
156155

157156
def convert(self, value, allowed_types):

0 commit comments

Comments
 (0)