|
1 | 1 | Customizing the Parser with Your Own Configuration |
2 | 2 | ================================================== |
3 | 3 |
|
| 4 | +:py:class:`~nameparser.config.Constants` is for application-level |
| 5 | +configuration, set once at startup: the shared module-level ``CONSTANTS`` |
| 6 | +instance is the only channel that reaches parses happening in code you don't |
| 7 | +own -- helpers, pipelines, a third-party library using nameparser internally |
| 8 | +-- the same role ``logging`` and ``locale`` play elsewhere. For anything |
| 9 | +scoped to one dataset, one library, or one test, pass your own ``Constants`` |
| 10 | +instance instead -- see the three explicit forms under "Module-level Shared |
| 11 | +Configuration Instance" below. |
| 12 | + |
4 | 13 | Recognition of titles, prefixes, suffixes and conjunctions is handled by |
5 | 14 | matching the lower case characters of a name piece with pre-defined sets |
6 | 15 | of strings located in :py:mod:`nameparser.config`. You can adjust |
@@ -428,13 +437,14 @@ making them lower case and removing periods. |
428 | 437 | Module-level Shared Configuration Instance |
429 | 438 | ------------------------------------------ |
430 | 439 |
|
431 | | -When you modify the configuration, by default this will modify the behavior all |
432 | | -HumanName instances. This could be a handy way to set it up for your entire |
433 | | -project, but it could also lead to some unexpected behavior because changing |
434 | | -the config on one instance could modify the behavior of another instance. |
435 | | -Parsing itself never modifies the configuration — only your own ``add`` and |
436 | | -``remove`` calls do — so the shared instance is safe to read concurrently, |
437 | | -e.g. parsing names on multiple threads. |
| 440 | +As established above, ``CONSTANTS`` is shared by every ``HumanName`` created |
| 441 | +without its own config -- that's what makes it the right place for |
| 442 | +application-level setup, and also the source of the one gotcha it carries: |
| 443 | +changing the config on one instance changes the behavior of every other |
| 444 | +instance that shares it, which can be surprising if you only meant to |
| 445 | +configure the one you're holding. Parsing itself never modifies the |
| 446 | +configuration — only your own ``add`` and ``remove`` calls do — so the shared |
| 447 | +instance is safe to read concurrently, e.g. parsing names on multiple threads. |
438 | 448 |
|
439 | 449 | .. doctest:: module config |
440 | 450 | :options: +ELLIPSIS, +NORMALIZE_WHITESPACE |
|
0 commit comments