Skip to content

Commit

Permalink
Fix mypy error for csv.Sniffer.sniff(delimiter)
Browse files Browse the repository at this point in the history
The type of the delimiter parameter to csv.Sniffer.sniff is str, so
that's what should be accepted here.

Also check to ensure that delimiters are single characters.
  • Loading branch information
victorlin committed Jun 30, 2023
1 parent 6b7a72c commit a5c173a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion augur/io/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,15 @@ def write_records_to_tsv(records, output_file):

def _get_delimiter(path: str, valid_delimiters: Iterable[str]):
"""Get the delimiter of a file given a list of valid delimiters."""

for delimiter in valid_delimiters:
if len(delimiter) != 1:
raise AugurError(f"Delimiters must be single-character strings. {delimiter!r} does not satisfy that condition.")

with open_file(path) as file:
try:
# Infer the delimiter from the first line.
return csv.Sniffer().sniff(file.readline(), valid_delimiters).delimiter
return csv.Sniffer().sniff(file.readline(), "".join(valid_delimiters)).delimiter
except csv.Error as error:
# This assumes all csv.Errors imply a delimiter issue. That might
# change in a future Python version.
Expand Down

0 comments on commit a5c173a

Please sign in to comment.