Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove scalar type validation #161

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading