Skip to content

Commit

Permalink
Combine append() and extend() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkZH committed Feb 22, 2024
1 parent 7e0081e commit b524c3a
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions chess/pgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ def remove_empty(self) -> None:
"""Remove empty comments from the comment list."""
self._comments = list(filter(None, self._comments))

def append(self, new_comment: str) -> None:
"""Append a new comment to the end of the comment list."""
self._comments.append(new_comment)

def extend(self, new_comments: list[str]) -> None:
"""Append several new comments to the end of the comment list."""
self._comments.extend(new_comments)
def append(self, new_comment: Union[str, list[str]]) -> None:
"""Append one or more new comments to the end of the comment list."""
if new_comment:
if isinstance(new_comment, str):
self._comments.append(new_comment)
else:
self._comments.extend(new_comment)

def insert(self, index: int, new_comment: str) -> None:
"""Insert a new comment before the specified index."""
Expand Down Expand Up @@ -494,14 +494,7 @@ def add_line(self, moves: Iterable[chess.Move], *, comment: Union[str, list[str]
starting_comment = ""

# Merge comment and NAGs.
if node.comment:
if isinstance(comment, str):
node.comment.append(comment)
else:
node.comment.extend(comment)
else:
node.comment.set(comment)

node.comment.append(comment)
node.nags.update(nags)

return node
Expand Down

0 comments on commit b524c3a

Please sign in to comment.