Skip to content

Commit 0740241

Browse files
derek73claude
andcommitted
Review feedback: tests, style fixes, and docs
Add tests for two code paths flagged in review: - test_phd_extracted_without_comma: covers fix_phd() extracting "Ph. D." from names without a comma (e.g. "John Smith Ph. D.") - test_roman_numeral_suffix_not_in_suffix_list: covers the is_roman_numeral(nxt) branch for VI-X, which are not in the suffix word lists and so are not caught by are_suffixes() first Other changes: - Replace list[T]() constructor style with typed annotations (list: T = []) in parser.py — same runtime behavior, idiomatic Python - Add LGPL license classifier to pyproject.toml (was present in setup.py) - Note pip >= 24.1 requirement for --group dev in CONTRIBUTING.md and AGENTS.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9ca29f3 commit 0740241

5 files changed

Lines changed: 20 additions & 5 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
55
## Commands
66

77
```bash
8-
# Install dev dependencies
8+
# Install dev dependencies (requires pip >= 24.1)
99
pip install --group dev
1010

1111
# Run all tests

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributing
44
Development Environment Setup
55
--------------------------------
66

7-
Install dev dependencies:
7+
Install dev dependencies (requires pip >= 24.1 for dependency group support):
88

99
pip install --group dev
1010

nameparser/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def group_contiguous_integers(data: Iterable[int]) -> list[tuple[int, int]]:
1919
return list of tuples containing first and last index
2020
position of contiguous numbers in a series
2121
"""
22-
ranges = list[tuple[int, int]]()
22+
ranges: list[tuple[int, int]] = []
2323
for key, group_with_indices in groupby(enumerate(data), lambda i: i[0] - i[1]):
2424
group = list(map(itemgetter(1), group_with_indices))
2525
if len(group) > 1:
@@ -755,7 +755,7 @@ def parse_pieces(self, parts: Iterable[str], additional_parts_count: int = 0) ->
755755
:rtype: list
756756
"""
757757

758-
output = list[str]()
758+
output: list[str] = []
759759
for part in parts:
760760
if not isinstance(part, (str, bytes)):
761761
raise TypeError("Name parts must be strings. "
@@ -822,7 +822,7 @@ def join_on_conjunctions(self, pieces: list[str], additional_parts_count: int =
822822

823823
contiguous_conj_i = group_contiguous_integers(conj_index)
824824

825-
delete_i = list[int]()
825+
delete_i: list[int] = []
826826
for cont_i in contiguous_conj_i:
827827
new_piece = " ".join(pieces[cont_i[0]: cont_i[1]+1])
828828
delete_i += list(range(cont_i[0]+1, cont_i[1]+1))

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dynamic = ["version"]
99
keywords = ["names", "parser"]
1010
classifiers = [
1111
"Intended Audience :: Developers",
12+
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
1213
"Operating System :: OS Independent",
1314
"Programming Language :: Python",
1415
"Programming Language :: Python :: 3",

tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,14 @@ def test_roman_numeral_initials(self) -> None:
12671267
self.m(hn.last, "I", hn)
12681268
self.m(hn.suffix, "", hn)
12691269

1270+
def test_roman_numeral_suffix_not_in_suffix_list(self) -> None:
1271+
# VI-X are not in the suffix word lists, so they reach the
1272+
# is_roman_numeral(nxt) branch rather than are_suffixes()
1273+
hn = HumanName("John Smith VI")
1274+
self.m(hn.first, "John", hn)
1275+
self.m(hn.last, "Smith", hn)
1276+
self.m(hn.suffix, "VI", hn)
1277+
12701278
# tests for Rev. title (Reverend)
12711279
def test124(self) -> None:
12721280
hn = HumanName("Rev. John A. Kenneth Doe")
@@ -1784,6 +1792,12 @@ def test_phd_with_erroneous_space(self) -> None:
17841792
self.m(hn.last, "Smith", hn)
17851793
self.m(hn.suffix, "Ph. D.", hn)
17861794

1795+
def test_phd_extracted_without_comma(self) -> None:
1796+
hn = HumanName("John Smith Ph. D.")
1797+
self.m(hn.first, "John", hn)
1798+
self.m(hn.last, "Smith", hn)
1799+
self.m(hn.suffix, "Ph. D.", hn)
1800+
17871801
def test_phd_conflict(self) -> None:
17881802
hn = HumanName("Adolph D")
17891803
self.m(hn.first, "Adolph", hn)

0 commit comments

Comments
 (0)