Skip to content

Commit 20255b3

Browse files
committed
Compat with chardet 7
1 parent 4ec53bf commit 20255b3

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

codespell_lib/_codespell.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,18 @@ def __init__(
223223

224224
def init_chardet(self) -> None:
225225
try:
226-
from chardet.universaldetector import UniversalDetector
226+
import chardet
227227
except ImportError as e:
228228
msg = (
229229
"There's no chardet installed to import from. "
230230
"Please, install it and check your PYTHONPATH "
231231
"environment variable"
232232
)
233233
raise ImportError(msg) from e
234+
try:
235+
from chardet import UniversalDetector
236+
except ImportError: # chardet < 7
237+
from chardet.universaldetector import UniversalDetector
234238

235239
self.encdetector = UniversalDetector()
236240

0 commit comments

Comments
 (0)