diff --git a/Lib/shutil.py b/Lib/shutil.py index b37bd082eee0c6..ab359fd15feb77 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -200,7 +200,9 @@ def copyfileobj(fsrc, fdst, length=0): # Localize variable access to minimize overhead. fsrc_read = fsrc.read fdst_write = fdst.write - while buf := fsrc_read(length): + while len(buf := fsrc_read(length)) == length: + fdst_write(buf) + if buf: fdst_write(buf) def _samefile(src, dst): diff --git a/Misc/NEWS.d/next/Library/2023-09-26-16-57-47.gh-issue-109936.tOr6cE.rst b/Misc/NEWS.d/next/Library/2023-09-26-16-57-47.gh-issue-109936.tOr6cE.rst new file mode 100644 index 00000000000000..63699785e455bb --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-09-26-16-57-47.gh-issue-109936.tOr6cE.rst @@ -0,0 +1 @@ +shutil.copyfileobj now correctly returns on EOF