Skip to content

Pass only supported context to custom encoders - #698

Open
Sskift wants to merge 2 commits into
python-poetry:masterfrom
Sskift:fix/encoder-context-subsets
Open

Sskift wants to merge 2 commits into
python-poetry:masterfrom
Sskift:fix/encoder-context-subsets

Conversation

@Sskift

@Sskift Sskift commented Nov 2, 2026

Copy link
Copy Markdown

Summary

Custom encoder dispatch currently sends both context keywords whenever an encoder declares _parent. An encoder that only accepts _parent therefore receives an unexpected _sort_keys argument; an encoder that only accepts _sort_keys silently misses its context.

Pass each context value only when the callback accepts that keyword or has **kwargs. Avoid binding the primary value argument twice when its name is _parent or _sort_keys. Legacy one-argument callbacks, positional-only arguments, callable objects, and partial functions keep their existing calling conventions. Errors raised inside an encoder are propagated without retrying it.

Validation on Windows / CPython 3.12.10:

  • The 16 new cases produce 10 failures and 6 passing controls against the original source.
  • All 1,240 tests pass with the fix.
  • Ruff lint/format and git diff --check pass.
  • Mypy checks the new test file and reports the same 33 baseline diagnostics.
  • A separate Codex agent independently reviewed this commit: 2,280 function-binding comparisons pass (880 fail on the original source), eight exception/return controls pass, and its isolated full suite passes all 1,240 tests. This is AI review, not human review.

Duplicate Check

  • I searched the open PRs and found none that already fixes this issue.
  • Targeted all-state encoder PR and signature issue searches found no matching dispatch fix.

Agent Drafting Metadata

  • Agent: OpenAI Codex
  • Model: Exact model identifier was not exposed to this worker.
  • Notes: Codex assisted investigation, implementation, regression tests, and this description. No human review is claimed.

@Sskift

Sskift commented Nov 4, 2026

Copy link
Copy Markdown
Author

Fixed the Python 3.9 CI failures in 1c42d44 by adding from __future__ import annotations to the new test module. The two failures were caused by evaluating Item | None in test callback annotations on Python 3.9; encoder dispatch itself was not changed.

Verified on macOS / CPython 3.9.6: the focused suite reproduces 2 failures before the fix and passes all 16 tests after it. The full suite now passes with 1,238 passed and 2 skipped. Ruff lint/format and git diff --check also pass. The branch is updated; fresh CI is pending.

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