Skip to content

Commit ab85669

Browse files
committed
clarify and fix doctests
1 parent 63d7bc3 commit ab85669

1 file changed

Lines changed: 18 additions & 35 deletions

File tree

docs/customize.rst

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ how you instantiate the :py:class:`~nameparser.parser.HumanName` class.
1717

1818
The first is via ``from nameparser.config import CONSTANTS``.
1919

20-
::
20+
.. doctest::
2121

2222
>>> from nameparser.config import CONSTANTS
2323
>>> CONSTANTS
@@ -26,7 +26,7 @@ The first is via ``from nameparser.config import CONSTANTS``.
2626
The other is the ``C`` attribute of a ``HumanName`` instance, e.g.
2727
``hn.C``.
2828

29-
::
29+
.. doctest::
3030

3131
>>> from nameparser import HumanName
3232
>>> hn = HumanName("Dean Robert Johns")
@@ -119,20 +119,11 @@ the config on one instance could modify the behavior of another instance.
119119
:options: +ELLIPSIS, +NORMALIZE_WHITESPACE
120120

121121
>>> from nameparser import HumanName
122-
>>> hn = HumanName("Dean Robert Johns")
123-
>>> hn.C.titles.add('dean')
122+
>>> instance = HumanName("")
123+
>>> instance.C.titles.add('dean')
124124
SetManager(set([u'msgt', ..., u'adjutant']))
125-
>>> hn
126-
<HumanName : [
127-
title: 'Dean'
128-
first: 'Robert'
129-
middle: ''
130-
last: 'Johns'
131-
suffix: ''
132-
nickname: ''
133-
]>
134-
>>> hn2 = HumanName("Dean Robert Johns")
135-
>>> hn2
125+
>>> other_instance = HumanName("Dean Robert Johns")
126+
>>> other_instance # Dean parses as title
136127
<HumanName : [
137128
title: 'Dean'
138129
first: 'Robert'
@@ -149,26 +140,17 @@ instantiating ``HumanName``. Each instance always has a ``C`` attribute, but if
149140
you didn't pass something falsey to the ``constants`` argument then it's a
150141
reference to the module-level config values with the behavior described above.
151142

152-
::
143+
.. doctest:: module config
144+
:options: +ELLIPSIS, +NORMALIZE_WHITESPACE
153145

154146
>>> from nameparser import HumanName
155-
>>> hn = HumanName("Dean Robert Johns", None)
156-
>>> hn.C.titles.add('dean')
147+
>>> instance = HumanName("Dean Robert Johns")
148+
>>> instance.has_own_config
149+
False
150+
>>> instance.C.titles.add('dean')
157151
SetManager(set([u'msgt', ..., u'adjutant']))
158-
>>> hn.parse_full_name() # need to refresh parse after changing config
159-
>>> hn
160-
<HumanName : [
161-
title: 'Dean'
162-
first: 'Robert'
163-
middle: ''
164-
last: 'Johns'
165-
suffix: ''
166-
nickname: ''
167-
]>
168-
>>> hn.has_own_config
169-
True
170-
>>> hn2 = HumanName("Dean Robert Johns")
171-
>>> hn2
152+
>>> other_instance = HumanName("Dean Robert Johns", None)
153+
>>> other_instance
172154
<HumanName : [
173155
title: ''
174156
first: 'Dean'
@@ -177,8 +159,8 @@ reference to the module-level config values with the behavior described above.
177159
suffix: ''
178160
nickname: ''
179161
]>
180-
>>> hn2.has_own_config
181-
False
162+
>>> other_instance.has_own_config
163+
True
182164

183165

184166
Refreshing the Parse
@@ -193,6 +175,7 @@ those changes with ``repr()``.
193175
::
194176

195177
>>> from nameparser import HumanName
178+
>>> from nameparser.config import CONSTANTS
196179
>>> hn = HumanName("Dean Robert Johns")
197180
>>> hn
198181
<HumanName : [
@@ -203,7 +186,7 @@ those changes with ``repr()``.
203186
suffix: ''
204187
nickname: ''
205188
]>
206-
>>> hn.C.titles.add('dean')
189+
>>> CONSTANTS.titles.add('dean')
207190
SetManager(set([u'msgt', ..., u'adjutant']))
208191
>>> hn
209192
<HumanName : [

0 commit comments

Comments
 (0)