diff --git a/deptry/imports/extractors/notebook_import_extractor.py b/deptry/imports/extractors/notebook_import_extractor.py index 71f7cf22..18b307b7 100644 --- a/deptry/imports/extractors/notebook_import_extractor.py +++ b/deptry/imports/extractors/notebook_import_extractor.py @@ -36,7 +36,7 @@ def _read_ipynb_file(cls, path_to_ipynb: Path) -> dict[str, Any] | None: try: with path_to_ipynb.open() as ipynb_file: notebook: dict[str, Any] = json.load(ipynb_file) - except (UnicodeDecodeError, ValueError): + except ValueError: try: with path_to_ipynb.open(encoding=cls._get_file_encoding(path_to_ipynb)) as ipynb_file: notebook = json.load(ipynb_file, strict=False) diff --git a/deptry/imports/extractors/python_import_extractor.py b/deptry/imports/extractors/python_import_extractor.py index 78394682..e240e9d8 100644 --- a/deptry/imports/extractors/python_import_extractor.py +++ b/deptry/imports/extractors/python_import_extractor.py @@ -20,7 +20,7 @@ def extract_imports(self) -> dict[str, list[Location]]: try: with self.file.open() as python_file: tree = ast.parse(python_file.read(), str(self.file)) - except (UnicodeDecodeError, ValueError): + except (SyntaxError, ValueError): try: with self.file.open(encoding=self._get_file_encoding(self.file)) as python_file: tree = ast.parse(python_file.read(), str(self.file))