Skip to content

Commit f2685d9

Browse files
gh-155212: Check for a directory before opening the file
Opening a directory fails with IsADirectoryError on Unix, but with PermissionError on Windows. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c3c96d7 commit f2685d9

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Tools/clinic/libclinic/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ def parse_file(
6969
except KeyError:
7070
raise ClinicError(f"Can't identify file type for file {filename!r}")
7171

72-
try:
73-
with open(filename, encoding="utf-8") as f:
74-
raw = f.read()
75-
except IsADirectoryError:
72+
if os.path.isdir(filename):
7673
raise ClinicError(f"Can't read file {filename!r}: it is a directory")
7774

75+
with open(filename, encoding="utf-8") as f:
76+
raw = f.read()
77+
7878
# exit quickly if there are no clinic markers in the file
7979
find_start_re = BlockParser("", language).find_start_re
8080
if not find_start_re.search(raw):

0 commit comments

Comments
 (0)