Skip to content

Commit 275360c

Browse files
committed
docs: document middle_name_as_last flag (#133)
1 parent 7a00311 commit 275360c

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

docs/customize.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Other editable attributes
8888
* :py:obj:`~nameparser.config.Constants.suffix_delimiter` - additional delimiter used to split suffix groups after comma-splitting, e.g. ``" - "`` for names like ``"Jane Smith, RN - CRNA"``. Defaults to ``None`` (disabled).
8989
* :py:obj:`~nameparser.config.Constants.initials_separator` - string placed between consecutive initials within the same name group (after the delimiter). Defaults to ``" "``, so ``"A. K."``; set to ``""`` for compact ``"A.K."``.
9090
* :py:obj:`~nameparser.config.Constants.patronymic_name_order` - If set, detects Russian formal-order names (``Surname GivenName Patronymic``) via a trailing East-Slavic patronymic suffix and rotates the parts to Western order (``first=GivenName``, ``middle=Patronymic``, ``last=Surname``). Opt-in; see subsection below.
91+
* :py:obj:`~nameparser.config.Constants.middle_name_as_last` - If set, folds middle names into the last name (``.last`` becomes what ``.surnames`` already was, ``.middle`` becomes empty). Opt-in; see subsection below.
9192

9293

9394
Russian Formal Name Order
@@ -117,6 +118,29 @@ patronymic-form surnames such as ``"David Michael Abramovich"``. Enable this
117118
flag only when your data is predominantly Russian formal-order names.
118119

119120

121+
Suppressing Middle Names
122+
~~~~~~~~~~~~~~~~~~~~~~~~~
123+
124+
Some naming systems have no middle-name concept — everything after the given
125+
name is lineage or family (e.g. Arabic patronymic chaining: given + father +
126+
grandfather + family). Enable ``middle_name_as_last`` to fold the middle name
127+
into the last name instead of splitting them::
128+
129+
>>> from nameparser import HumanName
130+
>>> from nameparser.config import Constants
131+
>>> C = Constants(middle_name_as_last=True)
132+
>>> hn = HumanName("Mohamad Ahmad Ali Hassan", constants=C)
133+
>>> hn.first, hn.middle, hn.last
134+
('Mohamad', '', 'Ahmad Ali Hassan')
135+
136+
The fold applies uniformly to comma input too, so both written forms of a name
137+
converge on the same result::
138+
139+
>>> hn2 = HumanName("Hassan, Mohamad Ahmad Ali", constants=C)
140+
>>> hn2.first, hn2.last
141+
('Mohamad', 'Ahmad Ali Hassan')
142+
143+
120144
Splitting last-name prefix particles
121145
-------------------------------------
122146

docs/release_log.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Release Log
2929
``middle="ahmed"``, ``last="salem"``). Disable via
3030
``CONSTANTS.first_name_prefixes.clear()``. **Default-on: changes parsing
3131
output for names with these prefixes.** (#150)
32+
- Add ``middle_name_as_last`` flag to ``Constants`` and ``HumanName`` for opt-in folding of middle names into the last name, for naming systems with no middle-name concept (e.g. Arabic patronymic chaining) (#133)
3233
* 1.2.1 - June 19, 2026
3334
- Fix ``initials()`` interpolating the literal ``None`` for empty name parts when ``empty_attribute_default = None`` (e.g. ``"J. None D."``); empty parts now render as an empty string and a fully-empty result returns ``empty_attribute_default``
3435
- Add ``python -m nameparser "Name String"`` command-line helper that prints a parsed name

0 commit comments

Comments
 (0)