diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index f2c6c44cb66..3545e258689 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -19,6 +19,7 @@ import argparse import configparser import fnmatch +import locale import os import re import sys @@ -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="")