Skip to content

Commit

Permalink
Merge pull request #161 from foarsitter/scalar_type_validation
Browse files Browse the repository at this point in the history
Remove scalar type validation
  • Loading branch information
foarsitter authored Dec 18, 2024
2 parents bb039c1 + 633cddc commit c13cc86
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
15 changes: 0 additions & 15 deletions src/requestmodel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,6 @@ def get_annotated_type(
else:
annotated_property = params.Query()

scalar_types = (params.Query, params.Path, params.Header, params.Cookie)

if isinstance(annotated_property, scalar_types) and is_complex:
# query params do accept lists
if not (isinstance(annotated_property, params.Query) and is_sequence):
annotated_name = annotated_property.__class__.__name__

# in 3.8 & 3.9 Dict does not have a __name__
if not hasattr(origin, "__name__"):
origin = get_origin(origin)
raise ValueError(
f"`{variable_key}` annotated as {annotated_name} "
f"can only be a scalar, not a `{origin.__name__}`"
)

return annotated_property


Expand Down
18 changes: 0 additions & 18 deletions tests/test_request_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,13 @@ def test_get_annotated_type() -> None:
assert isinstance(get_annotated_type("d", hints["d"]), params.Body)
assert isinstance(get_annotated_type("e", hints["e"]), params.Body)

with pytest.raises(ValueError, match="can only be a scalar"):
assert isinstance(get_annotated_type("f", hints["f"]), params.Path)

with pytest.raises(ValueError, match="can only be a scalar"):
assert isinstance(get_annotated_type("g", hints["g"]), params.Query)


def test_annotated_type() -> None:
assert isinstance(
get_annotated_type("w", Annotated[List[str], params.Query()]), params.Query
)
assert isinstance(get_annotated_type("w", List[str]), params.Query)

with pytest.raises(
ValueError,
match="`x` annotated as Query can only be a scalar, not a `SimpleResponse`",
):
get_annotated_type("x", Annotated[SimpleResponse, params.Query()])

with pytest.raises(
ValueError,
match="`y` annotated as Query can only be a scalar, not a `(.)ict`",
):
get_annotated_type("y", Annotated[Dict[str, str], params.Query()])


def test_field_annotation_is_sequence() -> None:
assert field_annotation_is_sequence(str) is False
Expand Down

0 comments on commit c13cc86

Please sign in to comment.