Skip to content

Commit

Permalink
fix: pr suggestion
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Culler <[email protected]>
  • Loading branch information
lengau and mattculler authored Sep 17, 2024
1 parent 0aad7a6 commit 1370b55
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions craft_grammar/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,33 @@ def _validate_grammar_list( # noqa: PLR0912
pass
else:
continue
if issubclass(type_, str):
if isinstance(item, dict):
errors.append(
pydantic_core.InitErrorDetails(
type="value_error",
loc=(index,),
input=item,
ctx={
"error": ValueError(
f"value must be a str or valid grammar dict: {input_value!r}",
),
},
),
)
else:
raise pydantic.ValidationError.from_exception_data(
title=f"Grammar[{type_.__name__}]",
line_errors=[
pydantic_core.InitErrorDetails(
type="string_type",
loc=(),
input=item,
),
],
)
break
else:
if not issubclass(type_, str):
raise ValueError( # noqa: TRY004
_format_type_error(type_, input_value),
)
if not isinstance(item, dict):
raise pydantic.ValidationError.from_exception_data(
title=f"Grammar[{type_.__name__}]",
line_errors=[
pydantic_core.InitErrorDetails(
type="string_type",
loc=(),
input=item,
),
],
)
errors.append(
pydantic_core.InitErrorDetails(
type="value_error",
loc=(index,),
input=item,
ctx={
"error": ValueError(
f"value must be a str or valid grammar dict: {input_value!r}",
),
},
),
)

if errors:
raise pydantic.ValidationError.from_exception_data(
Expand Down

0 comments on commit 1370b55

Please sign in to comment.