Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nameparser/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,12 @@ def __repr__(self) -> str:
if text:
lines.append(f" {role.value}: {text!r}")
if self.ambiguities:
kinds = [a.kind.value for a in self.ambiguities]
lines.append(f" ambiguities: {kinds!r}")
items = [
f"{a.kind.value}: {'/'.join(t.text for t in a.tokens)}"
if a.tokens else a.kind.value
for a in self.ambiguities
]
lines.append(f" ambiguities: {items!r}")
body = "\n".join(lines)
return f"<ParsedName: [\n{body}\n]>" if lines else "<ParsedName: []>"

Expand Down
16 changes: 15 additions & 1 deletion tests/v2/test_reprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,21 @@ def test_parsedname_repr_includes_ambiguities_line_when_present() -> None:
pn = ParsedName("Van Johnson",
(van, Token("Johnson", Span(4, 11), Role.FAMILY)),
(Ambiguity(AmbiguityKind.PARTICLE_OR_GIVEN, "d", (van,)),))
assert "ambiguities: ['particle-or-given']" in repr(pn)
assert "ambiguities: ['particle-or-given: Van']" in repr(pn)


def test_parsedname_repr_distinguishes_same_kind_ambiguities_by_token() -> None:
# #431: two distinct suffix-or-name ambiguities about different
# words must not render as identical list entries.
ma = Token("MA", Span(11, 13), Role.SUFFIX)
v = Token("V", Span(14, 15), Role.SUFFIX)
pn = ParsedName(
"John Smith MA V",
(Token("John", Span(0, 4), Role.GIVEN),
Token("Smith", Span(5, 10), Role.FAMILY), ma, v),
(Ambiguity(AmbiguityKind.SUFFIX_OR_NAME, "d1", (ma,)),
Ambiguity(AmbiguityKind.SUFFIX_OR_NAME, "d2", (v,))))
assert "ambiguities: ['suffix-or-name: MA', 'suffix-or-name: V']" in repr(pn)


def test_empty_parsedname_repr() -> None:
Expand Down