Skip to content

Accept list pairs inside tuple constructor inputs - #160

Closed
Eric3-jp wants to merge 1 commit into
mewwts:masterfrom
Eric3-jp:fix/tuple-of-list-pairs
Closed

Eric3-jp wants to merge 1 commit into
mewwts:masterfrom
Eric3-jp:fix/tuple-of-list-pairs

Conversation

@Eric3-jp

Copy link
Copy Markdown

Dict((['a', 1], ['b', 2])) raises TypeError instead of producing {'a': 1, 'b': 2}. A tuple containing just one list pair raises IndexError. The constructor mistakes the outer tuple for the single-pair shortcut because it only recognizes a tuple, rather than a list, as the first nested pair. The same pairs already work in a list or generator, and tuple-of-pairs construction was introduced in #37.

Route tuples beginning with a list pair through the existing iterable-of-pairs path. This retains the single-pair tuple shortcut and the existing recursive conversion of nested dictionaries.

Add regression coverage for multiple list pairs, a single list pair with a nested dictionary, mixed list/tuple pairs with a tuple key, and the existing tuple-of-tuples form. Each case runs for both Dict and its test subclass.

Validation:

  • Before the source change, the eight new regression/control cases had six errors and two passes.
  • python -m unittest -q test_addict: all 136 tests passed on Windows with CPython 3.14.0 and Ubuntu 24.04 with CPython 3.11.16.
  • python -m compileall -q addict test_addict.py and git diff --check: passed.

The older Python versions in the CI matrix were not run locally.

Developed with assistance from OpenAI Codex.

@Eric3-jp Eric3-jp closed this by deleting the head repository Sep 23, 2026
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