Skip to content

SetManager.__contains__ is the lone non-normalizing membership check #244

Description

@derek73

After #238's follow-ups on PR #240, SetManager normalizes everywhere — add(), remove(), the constructor, and all set operators apply lc() (lowercase, strip leading/trailing periods). __contains__ is now the single exception:

from nameparser.config import Constants

c = Constants()
'Dr.' in c.titles        # False — raw membership
c.titles.remove('Dr.')   # removes 'dr' — normalized
c.titles & ['Dr.']       # matches 'dr' — normalized

A user who checks 'Dr.' in c.titles, sees False, and concludes their config never took effect is misled — every other operation on the same value succeeds.

Fix options: normalize str values in __contains__ (lc(value) in self.elements; the parser's own lc(piece) in ... calls are unaffected since lc is idempotent), or document raw membership as intended. Normalizing seems right for consistency. Note the ABC comparison mixins (__le__, __eq__) route through __contains__/element iteration, so check those semantics while at it.

Found by review of PR #240 — the asymmetry predates that PR (add/remove already normalized), but the PR widens it: seven operations normalize, one membership check doesn't.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions