Skip to content

Commit

Permalink
fix(imports): handle SyntaxError (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner authored Jun 18, 2023
1 parent 743b22f commit 11aabee
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deptry/imports/extractors/notebook_import_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion deptry/imports/extractors/python_import_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 11aabee

Please sign in to comment.