From c667b85a7f8bb599f13fa169cb11a0dcc3eb9d98 Mon Sep 17 00:00:00 2001 From: Miguel Gaiowski Date: Mon, 14 May 2018 22:13:48 -0700 Subject: [PATCH] Check for broken symlinks before checking file data (#202) --- black.py | 2 +- tests/test_black.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/black.py b/black.py index 913fe8d..a113169 100644 --- a/black.py +++ b/black.py @@ -2494,7 +2494,7 @@ def gen_python_files_in_dir(path: Path) -> Iterator[Path]: yield from gen_python_files_in_dir(child) - elif child.suffix in PYTHON_EXTENSIONS: + elif child.is_file() and child.suffix in PYTHON_EXTENSIONS: yield child diff --git a/tests/test_black.py b/tests/test_black.py index cf20945..bc133ca 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -695,6 +695,13 @@ class BlackTestCase(unittest.TestCase): result = CliRunner().invoke(black.main, []) self.assertEqual(result.exit_code, 0) + def test_broken_symlink(self) -> None: + with cache_dir() as workspace: + symlink = workspace / "broken_link.py" + symlink.symlink_to("nonexistent.py") + result = CliRunner().invoke(black.main, [str(workspace.resolve())]) + self.assertEqual(result.exit_code, 0) + def test_read_cache_line_lengths(self) -> None: with cache_dir() as workspace: path = (workspace / "file.py").resolve() -- 2.39.2