Skip to content

Preserve required fields in repr helpers - #757

Open
Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/repr-required-fields
Open

Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/repr-required-fields

Conversation

@Gambit-Checkmate

Copy link
Copy Markdown

The change

Fixes #756.

Always include required fields when an attribute is listed as both required and optional. Apply the omission predicate only to optional-only fields in format_exp_repr and format_nonexp_repr. Field order and deduplication are preserved.

Both regressions fail on d31d821 and pass with the patch. They cover default omission of None, a custom predicate, and optional-only fields that are retained or omitted. The full Windows CPython 3.13.13 unit and doctest suite reports 776 passed, 1 skipped and 22 subtests passed. The focused function utility tests, Ruff E9/F, Python 3.7 syntax check, sdist/wheel builds and diff checks passed. A Linux Python 3.10.12 smoke test also passed.

The backstory

This follows earlier contributions discussed in #601 and #609. I found this by passing overlapping field lists to the repr helpers and comparing the output with the documented required-field behavior.

AI assistance

  • Harness/tooling: OpenAI Codex, GitHub CLI and pytest.
  • Model: GPT-6 family. The exact serving identifier is unavailable.
  • Relevant original prompt excerpt: “没有合适公开 issue 时可以检查代码、复现真实缺陷,确认无重复后报告问题并提交独立修复。”

@Ekko82 Ekko82 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.

format_exp_repr and format_nonexp_repr now skip opt_key for a required string that is also listed as optional. With opt_key=lambda value: value < 0, the base raises TypeError, while 417de49 renders the required field and filters the numeric optional fields. A recording predicate confirms the required value is skipped. On Windows/Python 3.13.9, all eight public-API checks and the three selected original formatting tests pass, including required-only, field-order and deduplication controls.

This branch has not been deployed

No deployments
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.

Repr helpers can omit required attributes also listed as optional

2 participants