Skip to content

Commit

Permalink
csv: make logger optional
Browse files Browse the repository at this point in the history
  • Loading branch information
purarue committed Nov 13, 2024
1 parent 4f2fa34 commit f4a71a7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions my/utils/parse_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import logging

from pathlib import Path
from typing import Callable, Iterator, TypeVar
from typing import Callable, Iterator, TypeVar, Optional

T = TypeVar("T")


def parse_csv_file(
histfile: Path,
parse_function: Callable[[str], Iterator[T]],
logger: logging.Logger,
logger: Optional[logging.Logger] = None,
) -> Iterator[T]:
"""
Parses a CSV file using parse_function, yield results from that function.
Expand All @@ -25,5 +25,6 @@ def parse_csv_file(
if "\0" not in data:
raise RuntimeError(f"Could not parse {histfile}: {e}") from e
else:
logger.warning("Found NUL byte in %s: %s", histfile, e)
if logger:
logger.warning("Found NUL byte in %s: %s", histfile, e)
yield from parse_function(data.replace("\0", ""))

0 comments on commit f4a71a7

Please sign in to comment.