Skip to content

Non-descriptor Constants set attributes accept bare-string assignment; substring 'in' silently corrupts parsing #241

Description

@derek73

The four cached-union attributes (titles, prefixes, suffix_acronyms, suffix_not_acronyms) are guarded by _CachedUnionMember.__set__, which rejects non-SetManager assignment with a clear TypeError. The other five set-backed attributes — first_name_titles, conjunctions, bound_first_names, non_first_name_prefixes, suffix_acronyms_ambiguous — are plain instance attributes (config/init.py, assigned in Constants.__init__), so this is accepted silently:

from nameparser import HumanName
from nameparser.config import Constants

c = Constants()
c.conjunctions = 'and'      # attribute is now a plain str
HumanName('John An Smith', constants=c)
# first='John An Smith', middle='', last=''   (default: John / An / Smith)

Root cause: membership checks like piece.lower() in self.C.conjunctions become substring tests on a str ('an' in 'and' is True), so parsing silently degrades with no traceback pointing at the bad assignment.

The constructor path is guarded since #238 (Constants(conjunctions='and') raises). This is the residual assignment gap. Distinct from #239, which is about hn.C assignment on HumanName, not attribute assignment on Constants.

Fix: guard these five like the cached-union four — a lighter shared descriptor enforcing isinstance(value, SetManager) (without the _pst invalidation), reusing the existing error-message style.

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