Skip to content

feat: Add pathlib.Path normalization to string representation#29

Merged
alesanfra merged 3 commits intotoon-format:mainfrom
smortezah:feat/extend-normalization
Mar 17, 2026
Merged

feat: Add pathlib.Path normalization to string representation#29
alesanfra merged 3 commits intotoon-format:mainfrom
smortezah:feat/extend-normalization

Conversation

@smortezah
Copy link
Contributor

Description

Added support for normalizing common Python types (pathlib.Path objects) to JSON-compatible values during TOON encoding. This enhancement makes it easier to serialize Python applications that work with file paths.

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Test coverage improvement

Related Issues

Closes # (if applicable)

Changes Made

  • Extended normalize_value() function in src/toon_format/normalize.py:

    • Added pathlib.Path, PurePath, PurePosixPath, PureWindowsPath → string conversion
    • Updated module docstring to document new type conversions
    • Added detailed examples in function docstring
  • Added comprehensive test coverage in tests/test_normalization.py:

    • TestPathNormalization class with 5 tests covering Path object handling

SPEC Compliance

  • This PR implements/fixes spec compliance
  • Spec section(s) affected: Section 3 (Normalization) - extends Python-specific normalization
  • Spec version: v1.5 (maintains compatibility while extending Python support)

Testing

  • All existing tests pass
  • Added new tests for changes
  • Tested on Python 3.8
  • Tested on Python 3.9
  • Tested on Python 3.10
  • Tested on Python 3.11
  • Tested on Python 3.12

Test Output

$ pytest tests/test_normalization.py::TestPathNormalization -v
======================== test session starts =========================
collected 5 tests

tests/test_normalization.py::TestPathNormalization::test_path_to_string PASSED
tests/test_normalization.py::TestPathNormalization::test_relative_path PASSED
tests/test_normalization.py::TestPathNormalization::test_pure_path PASSED
tests/test_normalization.py::TestPathNormalization::test_path_in_array PASSED
tests/test_normalization.py::TestPathNormalization::test_path_in_nested_structure PASSED

$ pytest tests/ -v
======================== 818 passed, 13 skipped in 2.34s =========================

@smortezah smortezah requested a review from a team as a code owner November 10, 2025 14:54
@johannschopplich
Copy link
Contributor

@alesanfra this one's been sitting for a while and looks solid to me – happy if you want to take a quick look and merge if it checks out! 🙌

Copy link

@alesanfra alesanfra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alesanfra alesanfra merged commit 9086144 into toon-format:main Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants