Skip to content

Commit 834cd27

Browse files
committed
Catch UnicodeDecodeError when attempting to read excluded files.
Fixes #1579. PiperOrigin-RevId: 606459110
1 parent f9c7c6c commit 834cd27

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

pytype/file_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def is_file_script(filename, directory=None):
148148
# of course we assume that they start with a shebang
149149
file_path = expand_path(filename, directory)
150150
if path_utils.isfile(file_path):
151-
with open(file_path, "r") as file:
152-
line = file.readline().rstrip().lower()
151+
with open(file_path, "r") as fi:
152+
try:
153+
line = fi.readline().rstrip().lower()
154+
except UnicodeDecodeError:
155+
return False
153156
return re.fullmatch(r"#!.+python3?", line) is not None

0 commit comments

Comments
 (0)