Skip to content

TupleManager string inputs: cryptic ValueError for bare strings, silent key/value shredding for 2-char elements #242

Description

@derek73

TupleManager (and RegexTupleManager) inherit dict.__init__ unchanged, so string inputs behave inconsistently with the guarded SetManager (#238):

from nameparser.config import Constants, TupleManager

Constants(capitalization_exceptions='ab')
# ValueError: dictionary update sequence element #0 has length 1; 2 is required
# loud, but names no argument and suggests no fix

TupleManager(['ab', 'cd'])                   # {'a': 'b', 'c': 'd'} — silent
Constants(capitalization_exceptions=['ii'])  # {'i': 'i'} — silent

The bare-string case fails loudly but cryptically (dict internals, ValueError where the sibling set-backed args now raise a friendly TypeError). The worse case is the silent one: an iterable of 2-character strings is a valid dict-update sequence, so each string shreds into a key/value pair with no error — same family as #238 through the mapping constructor.

Fix: give TupleManager an __init__ that rejects str/bytes outright (mirroring SetManager._reject_bare_string's message style) and rejects non-tuple string elements, closing the 2-char variant.

Found by review of PR #240 — pre-existing, unrelated to that change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions