Skip to content

Commit

Permalink
move version guard to compat.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Dec 15, 2023
1 parent 720d918 commit e9ba14c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 5 additions & 0 deletions hypothesis-python/src/hypothesis/internal/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ def dataclass_asdict(obj, *, dict_factory=dict):
return _asdict_inner(obj, dict_factory)


if sys.version_info[:2] >= (3, 12):
# see issue #3812
dataclass_asdict = dataclasses.asdict


def _asdict_inner(obj, dict_factory):
if dataclasses._is_dataclass_instance(obj):
if dict_factory is dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ def to_jsonable(obj: object) -> object:
and dcs.is_dataclass(obj)
and not isinstance(obj, type)
):
if sys.version_info[:2] < (3, 12):
# see issue #3812
return to_jsonable(dataclass_asdict(obj))
else: # pragma: no cover
return to_jsonable(dcs.asdict(obj))
return to_jsonable(dataclass_asdict(obj))
if attr.has(type(obj)):
return to_jsonable(attr.asdict(obj, recurse=False)) # type: ignore
if (pyd := sys.modules.get("pydantic")) and isinstance(obj, pyd.BaseModel):
Expand Down

0 comments on commit e9ba14c

Please sign in to comment.