Skip to content

Commit ede221d

Browse files
committed
Fix Optional bool autoconversions
1 parent c267708 commit ede221d

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
```py
1313
from flask import Flask
1414
from typing import List, Optional
15-
from flask_parameter_validation import ValidateParameters, Route, Json
15+
from flask_parameter_validation import ValidateParameters, Route, Json, Query
1616

1717
app = Flask(__name__)
1818

@@ -24,10 +24,12 @@ def hello(
2424
username: str = Json(min_length=5, blacklist="<>"),
2525
age: int = Json(min_int=18, max_int=99),
2626
nicknames: List[str] = Json(),
27-
password_expiry: Optional[int] = Json(5)
27+
password_expiry: Optional[int] = Json(5),
28+
is_admin: bool = Query(False)
2829
):
2930
return "Hello World!"
3031

32+
3133
if __name__ == "__main__":
3234
app.run()
3335
```

flask_parameter_validation/parameter_validation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,21 @@ def nested_func(**kwargs):
8181
allowed_types = (param_annotation,)
8282

8383
# If query parameter, try converting to match
84-
if param_type.__class__ == Query:
84+
if param_type.__class__ == Query and type(user_input) == str: # noqa: E501
8585
# int conversion
86-
if param_annotation == int:
86+
if int in allowed_types:
8787
try:
8888
user_input = int(user_input)
8989
except ValueError:
9090
pass
9191
# float conversion
92-
if param_annotation == float:
92+
if float in allowed_types:
9393
try:
9494
user_input = float(user_input)
9595
except ValueError:
9696
pass
9797
# bool conversion
98-
elif param_annotation == bool:
98+
elif bool in allowed_types:
9999
if user_input.lower() == "true":
100100
user_input = True
101101
elif user_input.lower() == "false":

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111

1212
setup(
1313
name='Flask-Parameter-Validation',
14-
version='1.0.18',
14+
version='1.0.21',
1515
url='https://github.com/Ge0rg3/Flask-Parameter-Validation',
1616
license='MIT',
1717
author='George Omnet',
1818
author_email='[email protected]',
1919
description='Get and validate all Flask input parameters with ease.',
2020
long_description=long_description,
2121
long_description_content_type='text/markdown',
22-
packages=['flask_parameter_validation', 'flask_parameter_validation.parameter_types'],
22+
packages=['flask_parameter_validation',
23+
'flask_parameter_validation.parameter_types'],
2324
zip_safe=False,
2425
include_package_data=True,
2526
platforms='any',

0 commit comments

Comments
 (0)