Skip to content

Commit

Permalink
Revert "Fix Json strategy serialization failure"
Browse files Browse the repository at this point in the history
This reverts commit f18f623.
  • Loading branch information
SergioSim committed Apr 24, 2022
1 parent f18f623 commit 5ce6912
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
13 changes: 2 additions & 11 deletions pydantic/_hypothesis_plugin.py
Expand Up @@ -27,7 +27,7 @@
import json
import math
from fractions import Fraction
from typing import Any, Callable, Dict, Type, Union, cast, overload
from typing import Callable, Dict, Type, Union, cast, overload

import hypothesis.strategies as st

Expand Down Expand Up @@ -212,15 +212,6 @@ def inner(f): # type: ignore
# Type-to-strategy resolver functions


def is_base_model(cls: Any) -> bool:
"""Returns True if the given class is a subclass of the pydantic BaseModel."""

try:
return issubclass(cls, pydantic.BaseModel)
except TypeError:
return False


@resolves(pydantic.JsonWrapper)
def resolve_json(cls): # type: ignore[no-untyped-def]
try:
Expand All @@ -232,7 +223,7 @@ def resolve_json(cls): # type: ignore[no-untyped-def]
extend=lambda x: st.lists(x) | st.dictionaries(st.text(), x), # type: ignore
)
return st.builds(
cls.inner_type.json if is_base_model(getattr(cls, 'inner_type', None)) else json.dumps,
json.dumps,
inner,
ensure_ascii=st.booleans(),
indent=st.none() | st.integers(0, 16),
Expand Down
1 change: 0 additions & 1 deletion tests/test_hypothesis_plugin.py
Expand Up @@ -67,7 +67,6 @@ class JsonModel(pydantic.BaseModel):
json_str: pydantic.Json[str]
json_int_or_str: pydantic.Json[typing.Union[int, str]]
json_list_of_float: pydantic.Json[typing.List[float]]
json_pydantic_model: pydantic.Json[pydantic.BaseModel]

class ConstrainedNumbersModel(pydantic.BaseModel):
conintt: pydantic.conint(gt=10, lt=100)
Expand Down

0 comments on commit 5ce6912

Please sign in to comment.