Skip to content

Commit

Permalink
Fix AssertionError when opening with chardet
Browse files Browse the repository at this point in the history
  • Loading branch information
n-thumann committed Mar 13, 2023
1 parent b8c5bb2 commit a326b44
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import argparse
import configparser
import fnmatch
import locale
import os
import re
import sys
Expand Down Expand Up @@ -228,7 +229,8 @@ def open_with_chardet(self, filename: str) -> Tuple[List[str], str]:
break
self.encdetector.close()
encoding = self.encdetector.result["encoding"]
assert encoding is not None # noqa: S101
if not encoding:
encoding = locale.getpreferredencoding(False)

try:
f = open(filename, encoding=encoding, newline="")
Expand Down

0 comments on commit a326b44

Please sign in to comment.