Skip to content

Commit 7e479a5

Browse files
committed
Add type stubs
1 parent cbad23f commit 7e479a5

11 files changed

Lines changed: 216 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ your names to `TEST_NAMES`. A test attempts to try the 3 different
6363
comma variations of these names automatically and make sure things
6464
don't blow up, so it can be a helpful regression indicator.
6565

66+
Type Hints
67+
----------
68+
69+
Make sure to update the [type stubs](https://typing.python.org/en/latest/guides/writing_stubs.html) (`.pyi` files) to reflect changes in the code. The repository contains a configuration for [mypy](https://mypy-lang.org/).
6670

6771
New Releases
6872
------------

nameparser/__init__.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from nameparser.parser import HumanName as HumanName
2+
3+
VERSION: tuple[int]
4+
__version__: str
5+
__author_email__: str
6+
__url__: str

nameparser/config/__init__.pyi

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import re
2+
from collections.abc import Set
3+
from typing import Collection, Dict, Generic, Iterable, Iterator, Mapping, TypeVar
4+
5+
from nameparser.config.capitalization import CAPITALIZATION_EXCEPTIONS as CAPITALIZATION_EXCEPTIONS
6+
from nameparser.config.conjunctions import CONJUNCTIONS as CONJUNCTIONS
7+
from nameparser.config.prefixes import PREFIXES as PREFIXES
8+
from nameparser.config.regexes import REGEXES as REGEXES
9+
from nameparser.config.suffixes import SUFFIX_ACRONYMS as SUFFIX_ACRONYMS
10+
from nameparser.config.suffixes import SUFFIX_NOT_ACRONYMS as SUFFIX_NOT_ACRONYMS
11+
from nameparser.config.titles import FIRST_NAME_TITLES as FIRST_NAME_TITLES
12+
from nameparser.config.titles import TITLES as TITLES
13+
14+
DEFAULT_ENCODING: str
15+
16+
17+
T = TypeVar('T')
18+
19+
20+
class SetManager(Generic[T], Set):
21+
elements: Set[T]
22+
def __init__(self, elements: Iterable[T]) -> None: ...
23+
def __call__(self) -> Set[T]: ...
24+
def __iter__(self) -> Iterator[T]: ...
25+
def __contains__(self, value: object) -> bool: ...
26+
def __len__(self) -> int: ...
27+
def next(self) -> T: ...
28+
count: int
29+
def __next__(self) -> T: ...
30+
def add_with_encoding(self, s: T, encoding: str | None = None) -> None: ...
31+
def add(self, *strings: str) -> None: ...
32+
def remove(self, *strings: str) -> None: ...
33+
34+
35+
class TupleManager(Dict[str, T]):
36+
def __getattr__(self, attr: str) -> T: ...
37+
def __setattr__(self, attr: str, value: T) -> None: ...
38+
def __delattr__(self, attr: str) -> None: ...
39+
def __reduce__(self) -> tuple[type[TupleManager], tuple, Mapping[str, T]]: ...
40+
41+
42+
class Constants:
43+
string_format: str
44+
initials_format: str
45+
initials_delimiter: str
46+
empty_attribute_default: str
47+
capitalize_name: bool
48+
force_mixed_case_capitalization: bool
49+
prefixes: SetManager[str]
50+
suffix_acronyms: SetManager[str]
51+
suffix_not_acronyms: SetManager[str]
52+
titles: SetManager[str]
53+
first_name_titles: SetManager[str]
54+
conjunctions: SetManager[str]
55+
capitalization_exceptions: TupleManager[str]
56+
regexes: TupleManager[re.Pattern]
57+
@property
58+
def suffixes_prefixes_titles(self) -> SetManager[str]: ...
59+
def __init__(
60+
self,
61+
prefixes: Collection[str] = PREFIXES,
62+
suffix_acronyms: Collection[str] = SUFFIX_ACRONYMS,
63+
suffix_not_acronyms: Collection[str] = SUFFIX_NOT_ACRONYMS,
64+
titles: Collection[str] = TITLES,
65+
first_name_titles: Collection[str] = FIRST_NAME_TITLES,
66+
conjunctions: Collection[str] = CONJUNCTIONS,
67+
capitalization_exceptions: Collection[tuple[str, str]] = CAPITALIZATION_EXCEPTIONS,
68+
regexes: Collection[tuple[str, re.Pattern]] = REGEXES,
69+
) -> None: ...
70+
71+
72+
CONSTANTS: Constants
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CAPITALIZATION_EXCEPTIONS: set[tuple[str, str]]

nameparser/config/conjunctions.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONJUNCTIONS: set[str]

nameparser/config/prefixes.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PREFIXES: set[str]

nameparser/config/regexes.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import re
2+
3+
re_emoji: re.Pattern
4+
REGEXES: set[tuple[str, re.Pattern]]

nameparser/config/suffixes.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SUFFIX_NOT_ACRONYMS: set[str]
2+
SUFFIX_ACRONYMS: set[str]

nameparser/config/titles.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FIRST_NAME_TITLES: set[str]
2+
TITLES: set[str]

nameparser/parser.pyi

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
from typing import Iterable, Iterator, Literal
2+
3+
from nameparser.config import CONSTANTS, DEFAULT_ENCODING, Constants
4+
5+
ENCODING: str
6+
7+
8+
def group_contiguous_integers(data: Iterable[int]) -> list[tuple[int, int]]:
9+
...
10+
11+
12+
class HumanName:
13+
C: Constants
14+
original: str
15+
unparsable: bool
16+
encoding: str
17+
string_format: str
18+
initials_format: str
19+
initials_delimiter: str
20+
21+
def __init__(
22+
self,
23+
full_name: str = '',
24+
constants: Constants = CONSTANTS,
25+
encoding: str = DEFAULT_ENCODING,
26+
string_format: str | None = None,
27+
initials_format: str | None = None,
28+
initials_delimiter: str | None = None,
29+
first: str | None = None,
30+
middle: str | None = None,
31+
last: str | None = None,
32+
title: str | None = None,
33+
suffix: str | None = None,
34+
nickname: str | None = None,
35+
) -> None: ...
36+
37+
def __iter__(self) -> Iterator[str]: ...
38+
def __len__(self) -> int: ...
39+
def __eq__(self, other: object) -> bool: ...
40+
def __ne__(self, other: object) -> bool: ...
41+
def __getitem__(self, key: str | slice[int, int, int | None]) -> str: ...
42+
def __setitem__(self, key: str, value: str | Iterable[str]) -> None: ...
43+
def next(self) -> str: ...
44+
def __next__(self) -> str: ...
45+
def __hash__(self) -> int: ...
46+
def as_dict(self, include_empty: bool = True) -> dict[str, str]: ...
47+
def initials_list(self) -> list[str]: ...
48+
def initials(self) -> list[str]: ...
49+
@property
50+
def has_own_config(self) -> bool: ...
51+
@property
52+
def title(self) -> str: ...
53+
@title.setter
54+
def title(self, value: str) -> str: ...
55+
@property
56+
def first(self) -> str: ...
57+
@first.setter
58+
def first(self, value: str) -> str: ...
59+
@property
60+
def middle(self) -> str: ...
61+
@middle.setter
62+
def middle(self, value: str) -> str: ...
63+
@property
64+
def last(self) -> str: ...
65+
@last.setter
66+
def last(self, value: str) -> str: ...
67+
@property
68+
def suffix(self) -> str: ...
69+
@suffix.setter
70+
def suffix(self, value: str) -> str: ...
71+
@property
72+
def nickname(self) -> str: ...
73+
@nickname.setter
74+
def nickname(self, value: str) -> str: ...
75+
@property
76+
def surnames_list(self) -> list[str]: ...
77+
@property
78+
def surnames(self) -> str: ...
79+
def is_title(self, value: str)-> bool: ...
80+
def is_conjunction(self, piece: str)-> bool: ...
81+
def is_prefix(self, piece: str)-> bool: ...
82+
def is_roman_numeral(self, value: str)-> bool: ...
83+
def is_suffix(self, piece: str)-> bool: ...
84+
def are_suffixes(self, pieces: str)-> bool: ...
85+
def is_rootname(self, piece: str)-> bool: ...
86+
def is_an_initial(self, value: str)-> bool: ...
87+
full_name: str
88+
def collapse_whitespace(self, string: str) -> str: ...
89+
def pre_process(self) -> None: ...
90+
def post_process(self) -> None: ...
91+
def fix_phd(self) -> None: ...
92+
def parse_nicknames(self) -> None: ...
93+
def squash_emoji(self) -> None: ...
94+
def handle_firstnames(self) -> None: ...
95+
title_list: list[str]
96+
first_list: list[str]
97+
middle_list: list[str]
98+
last_list: list[str]
99+
suffix_list: list[str]
100+
nickname_list: list[str]
101+
def parse_full_name(self) -> None: ...
102+
def parse_pieces(self, parts: Iterable[str], additional_parts_count: int = 0) -> str: ...
103+
def join_on_conjunctions(self, pieces: Iterable[str], additional_parts_count: int = 0) -> str: ...
104+
def cap_word(self, word: str, attribute: Literal['title', 'first', 'middle', 'last', 'suffix', 'nickname', 'surnames']) -> str: ...
105+
def cap_piece(self, piece: str, attribute: Literal['title', 'first', 'middle', 'last', 'suffix', 'nickname', 'surnames']) -> str: ...
106+
def capitalize(self, force: bool | None = None) -> None: ...
107+
def handle_capitalization(self) -> None: ...

0 commit comments

Comments
 (0)