Repository navigation
Preserve duck-typed mappings without testing their truth value - #147
Merged
Merged
Conversation
Use the existing key-iteration empty-object path to avoid dropping false-valued mappings or raising on ambiguous truth values. Add iterator-only mapping controls for formatting and sorting. Prepared with OpenAI Codex assistance.
Owner
|
Ah, the fix was easier than I thought it would be, because of the trailing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The follow-up noted in #145 still affects duck-typed mappings: a false-valued mapping with an
answerkey serializes as{}, and a mapping whose truth value raises cannot be encoded at all.Remove the early truth-value test in
_encode_dict. Its existing key-iteration path already returns{}when no encodable keys remain, so no additional buffering or mapping methods are needed. Regression tests cover false-valued mappings and mappings with an undefined truth value, including empty input, iterator-only keys, sorting, indentation and trailing commas. Remove the now-unused__len__from an existing protocol test fixture.Before the fix, the regressions produce one failing assertion and 32 error subcases. Afterward, all 95 tests pass on Windows/Python 3.14.3 and Ubuntu/Python 3.10.12. Windows line coverage is 100%; library/test Ruff, formatting, pylint, mypy, doctests and package builds pass. The runner interpreter fix in #146 is separate and is not included here; checks were invoked with the environment's explicit interpreter.
Developed and tested with OpenAI Codex assistance. This follows the maintainer's observation in #145, not a claimed production incident or independent human review.