Skip to content

Commit 624093b

Browse files
committed
move open() line inside the "try" block
1 parent 4123bb1 commit 624093b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Lib/shutil.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ def copyfile(src, dst, *, follow_symlinks=True):
253253
if not follow_symlinks and _islink(src):
254254
os.symlink(os.readlink(src), dst)
255255
else:
256-
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
257-
try:
256+
try:
257+
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
258258
# macOS
259259
if _HAS_FCOPYFILE:
260260
try:
@@ -277,12 +277,12 @@ def copyfile(src, dst, *, follow_symlinks=True):
277277

278278
copyfileobj(fsrc, fdst)
279279

280-
# Issue 43219, raise a less confusing exception
281-
except IsADirectoryError as e:
282-
if os.path.exists(dst):
283-
raise
284-
else:
285-
raise FileNotFoundError(f'Directory does not exist: {dst}') from e
280+
# Issue 43219, raise a less confusing exception
281+
except IsADirectoryError as e:
282+
if os.path.exists(dst):
283+
raise
284+
else:
285+
raise FileNotFoundError(f'Directory does not exist: {dst}') from e
286286

287287
return dst
288288

0 commit comments

Comments
 (0)