From 14cdf292468a813238d76ec67eb330aa30152267 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Sun, 19 Mar 2023 12:31:43 +0000 Subject: [PATCH] Fix nonsense error messages in shutil.py Attempting to copy a file onto a symlink to itself previously gave the error ``` shutil.Error: ['<', 'D', 'i', 'r', 'E', 'n', 't', 'r', 'y', ' ', "'", 's', 't', 'y', 'l', 'e', '.', 'c', 's', 's', "'", '>', ' ', 'a', 'n', 'd', ' ', "'", 'b', 'u', 'i', 'l', 'd', '/', 'h', 't', 'm', 'l', '/', 's', 't', 'y', 'l', 'e', '.', 'c', 's', 's', "'", ' ', 'a', 'r', 'e', ' ', 't', 'h', 'e', ' ', 's', 'a', 'm', 'e', ' ', 'f', 'i', 'l', 'e'] ``` --- Lib/shutil.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index 867925aa10cc04..c264b5d590512c 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -500,7 +500,11 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function, # catch the Error from the recursive copytree so that we can # continue with other files except Error as err: - errors.extend(err.args[0]) + if isinstance(err.args[0], list): + # this is a recursive error + errors.extend(err.args[0]) + else: + errors.append((srcname, dstname, str(err))) except OSError as why: errors.append((srcname, dstname, str(why))) try: