Skip to content

[rejected AI] fix(json): support os.PathLike serialization and guard dataclass class type in DefaultJSONProvider - #6145

Closed
vjymisal0 wants to merge 1 commit into
pallets:mainfrom
vjymisal0:fix/json-pathlike-and-dataclass-class-serialization
Closed

[rejected AI] fix(json): support os.PathLike serialization and guard dataclass class type in DefaultJSONProvider#6145
vjymisal0 wants to merge 1 commit into
pallets:mainfrom
vjymisal0:fix/json-pathlike-and-dataclass-class-serialization

Conversation

@vjymisal0

Copy link
Copy Markdown

Summary

  1. os.PathLike Serialization Support:
    • DefaultJSONProvider._default now supports os.PathLike objects (e.g. pathlib.Path, pathlib.PurePosixPath, pathlib.PureWindowsPath) by serializing them as strings (str(o)), matching standard library behavior and common web framework patterns.
  2. Dataclass Class Type Guard:
    • dataclasses.is_dataclass(o) returns True for both dataclass instances and dataclass class types. When passed a dataclass class, dataclasses.asdict(o) raised TypeError: asdict() should be called on dataclass instances, not on classes. Added and not isinstance(o, type) to properly allow it to fall through to the standard JSON serializability TypeError.

Tests

  • Added unit tests test_pathlike_serialization and test_dataclass_class_raises_typeerror in tests/test_json.py.
  • All 495 pytest unit tests pass cleanly.

@davidism

Copy link
Copy Markdown
Member

@davidism davidism closed this Aug 31, 2026
@davidism

Copy link
Copy Markdown
Member

I do not want to add more types to this. I do not care that the error on invalid data is different for some data, it's invalid regardless and would be fixed not caught.

@davidism davidism changed the title fix(json): support os.PathLike serialization and guard dataclass class type in DefaultJSONProvider [rejected AI] fix(json): support os.PathLike serialization and guard dataclass class type in DefaultJSONProvider Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants