Skip to content

Commit c2636cf

Browse files
committed
Fix list-argument fallthrough in is_conjunction/is_prefix after pylance cleanup
A prior pylance-warning cleanup collapsed the if/else in is_conjunction and is_prefix, but left the list branch falling through into the scalar return when no item matched, calling piece.lower()/lc(piece) on a list and raising AttributeError. Add the explicit `return False` after the loop, matching the same pattern already used in is_suffix.
1 parent b626fc2 commit c2636cf

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

nameparser/parser.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ def is_conjunction(self, piece: str) -> bool:
570570
for item in piece:
571571
if self.is_conjunction(item):
572572
return True
573-
else:
574-
return piece.lower() in self.C.conjunctions and not self.is_an_initial(piece)
573+
return False
574+
return piece.lower() in self.C.conjunctions and not self.is_an_initial(piece)
575575

576576
def is_prefix(self, piece: str) -> bool:
577577
"""
@@ -582,8 +582,8 @@ def is_prefix(self, piece: str) -> bool:
582582
for item in piece:
583583
if self.is_prefix(item):
584584
return True
585-
else:
586-
return lc(piece) in self.C.prefixes
585+
return False
586+
return lc(piece) in self.C.prefixes
587587

588588
def is_bound_first_name(self, piece: str) -> bool:
589589
"""Lowercased, leading/trailing-periods-stripped version of piece is in :py:attr:`~nameparser.config.Constants.bound_first_names`."""
@@ -641,6 +641,7 @@ def is_suffix(self, piece: str) -> bool:
641641
for item in piece:
642642
if self.is_suffix(item):
643643
return True
644+
return False
644645
else:
645646
return ((lc(piece).replace('.', '') in self.C.suffix_acronyms)
646647
or (lc(piece) in self.C.suffix_not_acronyms)) \
@@ -852,7 +853,7 @@ def fix_phd(self) -> None:
852853

853854
if match := _re.search(self._full_name):
854855
self.suffix_list.extend(match.groups())
855-
self._full_name = _re.sub('', self._full_name)
856+
self._full_name = _re.sub("", self._full_name)
856857

857858
def parse_nicknames(self) -> None:
858859
"""

0 commit comments

Comments
 (0)