Skip to content

0.2.0: generated source loads back every value it names - #4

Merged
trissim merged 2 commits into
mainfrom
refactor/L6-codegen
Oct 11, 2026
Merged

trissim merged 2 commits into
mainfrom
refactor/L6-codegen

Conversation

@trissim

@trissim trissim commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Part of OpenHCS consolidation surface L6. Pipelines persist as pycodify-generated .py files, so a formatter gap is data loss.

Fixes (each reproduced before the change)

  • Nested enums: a member of Outer.Mode rendered from m import Mode / Mode.FAST, an ImportError on load. Nested dataclasses and callables had the same bug.
  • Classes had no formatter and rendered as <class 'm.X'>, a SyntaxError on load.
  • FallbackFormatter wrote repr() for any value. Values with no formatter now raise TypeError.
  • Full mode replaced a None field typed as a dataclass with an all-None instance, so the value changed on load.
  • init=False fields were written as constructor keywords, a TypeError on load.

Adds

  • imported_name(module, qualname, context): the single qualified-name rule. Enum, class (TypeFormatter), callable, named-tuple and dataclass formatting all use it.
  • PythonSourceLiteral: values that spell their own source through source_fragment(context).
  • paths.py: document-level path factoring (path_root = Path(...), path_1 = path_root / 'x'), always on in generate_python_source. FormatContext.paths is a PathRendering family (plain, collecting, factored).
  • Exact formatting for frozenset, bytes, complex, non-finite floats, Flag combinations and named tuples. Sets are sorted so output is stable.

Removes (breaking, so 0.2.0): FormatContext.extensions/extension(), the context= argument of generate_python_source, FallbackFormatter, and the ObjectState hasattr probes, which move to objectstate.codegen in ObjectState 2.1.0. This also covers the unreleased 0.1.4 branch (b6-release-0.1.4).

Release order: release this first, then ObjectState 2.1.0, then repin OpenHCS.

Tests: local pytest passed (65). ruff, black --check and mypy on src/ report nothing. CI on main was already failing before this PR.

🤖 Generated with Claude Code

- imported_name: one qualified-name rule (import the root of __qualname__,
  spell the rest as attributes). Fixes nested enums (Outer.Mode.FAST imported
  Mode), nested dataclasses and callables; classes get a TypeFormatter instead
  of falling to repr.
- PythonSourceLiteral: values that spell their own source through one
  source_fragment(context) method.
- paths.py: document-level path factoring on FormatContext.paths;
  generate_python_source binds shared and repeated absolute paths once.
  FormatContext.extensions/extension() and the context= argument are removed.
- Values without a formatter raise TypeError (FallbackFormatter emitted repr).
- Full mode no longer replaces a None dataclass field with an all-None
  instance; init=False fields are skipped; ObjectState hasattr probes removed
  (objectstate.codegen owns lazy dataclasses).
- frozenset, bytes, complex, non-finite floats, Flag combinations and named
  tuples load back exactly.
- 0.2.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 11, 2026 12:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The contract is on native Path values: tests build absolute paths from this
platform's anchor (and tmp_path), assert the source spells them with the
platform's separators, and check the source loads back as equal Paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trissim
trissim merged commit e3e3d99 into main Oct 11, 2026
14 checks passed
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.

2 participants