Skip to content

Validate and reconstruct namedtuple fields in ExactSequence - #560

Open
xingzhao-ji wants to merge 1 commit into
alecthomas:masterfrom
xingzhao-ji:fix/exact-sequence-namedtuple
Open

xingzhao-ji wants to merge 1 commit into
alecthomas:masterfrom
xingzhao-ji:fix/exact-sequence-namedtuple

Conversation

@xingzhao-ji

@xingzhao-ji xingzhao-ji commented Oct 12, 2026 •

Copy link
Copy Markdown

ExactSequence accepts tuple inputs but reconstructs them with type(value)(generator). For named tuples, this either raises TypeError (zero or multiple fields) or silently stores the generator in a one-field record without validating its contents.

Use the same named-tuple detection and positional reconstruction already used by ordinary tuple schemas. Keep ordinary list/tuple reconstruction and validation error handling unchanged.

Five regression cases cover zero-, one-, and two-field named tuples, coercion, preserving the record type and original input, and invalid fields with default/custom messages inside a dictionary schema. The API docstring and changelog describe the fix.

Validation:

  • All five new cases fail on the original implementation and pass with the fix.
  • Configured test selection: 187 passed on Python 3.12.14 and 3.13.5.
  • Explicitly including both test modules (the configured filename filter excludes test_dataclasses.py): 205 passed on each Python version.
  • Independent review ran six ExactSequence tests and both test modules successfully.
  • Mypy 1.16.0 passes all 10 source files; git diff --check passes.
  • An additional module/README doctest run has three failures, reproduced unchanged on pristine HEAD. Ruff checks likewise report only existing E721 comparisons and legacy Unicode-prefix formatting differences.

Black, isort, flake8, and the full supported Python/OS matrix were not run in the existing environment. No claim of completed upstream CI is made.

This extends the existing named-tuple handling from #231 to ExactSequence; it does not change unordered-sequence matching.

@xingzhao-ji
xingzhao-ji marked this pull request as ready for review October 14, 2026 17:49
@xingzhao-ji
xingzhao-ji marked this pull request as draft October 14, 2026 17:50
@xingzhao-ji
xingzhao-ji marked this pull request as ready for review October 14, 2026 17:51

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.

1 participant