File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -883,10 +883,11 @@ def scan_compiled_extensions(
883883 elif suffix not in ignore_suffixes :
884884 # Path.walk() lists symlinks to directories as filenames
885885 # rather than dirnames, causing IsADirectoryError on open().
886+ # Broken symlinks raise FileNotFoundError on open().
886887 try :
887888 with filepath .open ("rb" ) as f :
888889 header = f .read (_MAGIC_HEADERS_READ )
889- except IsADirectoryError :
890+ except ( IsADirectoryError , FileNotFoundError ) :
890891 continue
891892 if header .startswith (magic_headers ):
892893 relpath = filepath .relative_to (root_dir )
Original file line number Diff line number Diff line change @@ -285,3 +285,11 @@ def test_scan_compiled_extensions(
285285 assert matches == [pathlib .Path (filename )]
286286 else :
287287 assert matches == []
288+
289+
290+ def test_scan_compiled_extensions_broken_symlink (tmp_path : pathlib .Path ) -> None :
291+ """Verify broken symlinks are skipped without raising an error."""
292+ broken_link = tmp_path / "broken_link"
293+ broken_link .symlink_to (tmp_path / "nonexistent_target" )
294+ matches = sources .scan_compiled_extensions (tmp_path )
295+ assert matches == []
You can’t perform that action at this time.
0 commit comments