Skip to content

Commit 76e85dc

Browse files
derek73claude
andcommitted
docs: introduce and properly describe the module-level constants
autodata on a re-export can't see the defining module's #: doc comments, so every module-level constant rendered its TYPE's docstring -- GIVEN_FIRST et al. showed tuple's 'Built-in immutable sequence', DEFAULT_NICKNAME_DELIMITERS showed frozenset's constructor help, UNSET rendered blank. Replace them with manual py:data directives carrying real descriptions, under two new reference sub-headings ('Name-order constants' -- stating that name_order accepts ONLY these three, arbitrary Role tuples raise -- and 'Delimiter defaults'). The customize table's name_order type cell now says 'one of the three exported order constants' instead of the tuple[Role, Role, Role] annotation that invited hand-rolled tuples. The #: comments stay in _policy.py for source readers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent f609d40 commit 76e85dc

3 files changed

Lines changed: 52 additions & 6 deletions

File tree

docs/customize.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ listed below.
6161
- Type
6262
- Effect
6363
* - ``name_order``
64-
- ``tuple[Role, Role, Role]``
64+
- one of the three exported order constants
6565
- Assigns positional (no-comma) input to given/middle/family in
6666
this order. Use the exported ``GIVEN_FIRST`` (default),
6767
``FAMILY_FIRST``, or ``FAMILY_FIRST_GIVEN_LAST`` constants.

docs/modules.rst

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,54 @@ Configuration
4747
.. autoclass:: nameparser.PolicyPatch
4848
:members:
4949

50-
.. autodata:: nameparser.UNSET
50+
.. py:data:: nameparser.UNSET
51+
52+
Sentinel meaning "this patch does not set this field" — the default
53+
of every :class:`~nameparser.PolicyPatch` field, distinguishable
54+
from every real value including ``None`` and ``False``.
5155

5256
.. autoclass:: nameparser.PatronymicRule
5357
:members:
5458

55-
.. autodata:: nameparser.GIVEN_FIRST
59+
Name-order constants
60+
^^^^^^^^^^^^^^^^^^^^
61+
62+
The three valid values for ``Policy(name_order=...)``. ``name_order``
63+
is deliberately restricted to these exported constants — an arbitrary
64+
tuple of :class:`~nameparser.Role` members raises ``ValueError``,
65+
because only these three orders have defined assignment semantics.
66+
67+
.. py:data:: nameparser.GIVEN_FIRST
68+
:value: (Role.GIVEN, Role.MIDDLE, Role.FAMILY)
69+
70+
Western order (the default): the first word of positional input is
71+
the given name, the last is the family name, everything between is
72+
middle.
73+
74+
.. py:data:: nameparser.FAMILY_FIRST
75+
:value: (Role.FAMILY, Role.GIVEN, Role.MIDDLE)
76+
77+
Family name first, given name second, remaining words middle —
78+
e.g. Hungarian, or East Asian order.
79+
80+
.. py:data:: nameparser.FAMILY_FIRST_GIVEN_LAST
81+
:value: (Role.FAMILY, Role.MIDDLE, Role.GIVEN)
82+
83+
Family name first, given name *last*, the words between middle —
84+
e.g. Vietnamese full-name order.
5685

57-
.. autodata:: nameparser.FAMILY_FIRST
86+
Delimiter defaults
87+
^^^^^^^^^^^^^^^^^^
5888

59-
.. autodata:: nameparser.FAMILY_FIRST_GIVEN_LAST
89+
.. py:data:: nameparser.DEFAULT_NICKNAME_DELIMITERS
90+
:value: frozenset({("'", "'"), ('"', '"'), ("(", ")")})
6091

61-
.. autodata:: nameparser.DEFAULT_NICKNAME_DELIMITERS
92+
The default :attr:`~nameparser.Policy.nickname_delimiters` set —
93+
quotes and parentheses. Build on it for additive customizations,
94+
e.g. ``nickname_delimiters=DEFAULT_NICKNAME_DELIMITERS |
95+
{("«", "»")}``; to *reroute* a pair to ``maiden``, just list it in
96+
:attr:`~nameparser.Policy.maiden_delimiters` (it is dropped from
97+
the effective nickname set automatically).
6298

6399
Locales
64100
~~~~~~~

nameparser/_policy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@ class PatronymicRule(StrEnum):
2121

2222
# Order-spec constants (#270). Each reads as its contents because roles
2323
# are named given/family, not first/last.
24+
25+
#: Western order (the default): the first word of positional input is
26+
#: the given name, the last is the family name, everything between is
27+
#: middle. One of the three valid ``Policy(name_order=...)`` values.
2428
GIVEN_FIRST = (Role.GIVEN, Role.MIDDLE, Role.FAMILY)
29+
#: Family name first, given name second, remaining words middle
30+
#: (e.g. Hungarian, or East Asian order). One of the three valid
31+
#: ``Policy(name_order=...)`` values.
2532
FAMILY_FIRST = (Role.FAMILY, Role.GIVEN, Role.MIDDLE)
33+
#: Family name first, given name LAST, words between middle
34+
#: (e.g. Vietnamese full-name order). One of the three valid
35+
#: ``Policy(name_order=...)`` values.
2636
FAMILY_FIRST_GIVEN_LAST = (Role.FAMILY, Role.MIDDLE, Role.GIVEN)
2737

2838
_NAME_ROLES = frozenset({Role.GIVEN, Role.MIDDLE, Role.FAMILY})

0 commit comments

Comments
 (0)