From c3ece693363351b1835a0fcd88cd2abef27950c2 Mon Sep 17 00:00:00 2001 From: aaron-fl <43595516+aaron-fl@users.noreply.github.com> Date: Thu, 13 Aug 2026 18:28:51 +0900 Subject: [PATCH] gh-102967: Don't pass None to seek(), simply truncate from the current position (GH-102968) (cherry picked from commit 7586115ce3adeb9133717f0a721fb05621dd6700) Co-authored-by: aaron-fl <43595516+aaron-fl@users.noreply.github.com> --- Lib/doctest.py | 3 ++- Misc/ACKS | 1 + .../Library/2023-03-23-19-47-05.gh-issue-102967.gfIYkN.rst | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2023-03-23-19-47-05.gh-issue-102967.gfIYkN.rst diff --git a/Lib/doctest.py b/Lib/doctest.py index 84951f46bf52bf4..071124d060a5204 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -291,7 +291,8 @@ def getvalue(self): return result def truncate(self, size=None): - self.seek(size) + if size is not None: + self.seek(size) StringIO.truncate(self) # Worst-case linear-time ellipsis matching. diff --git a/Misc/ACKS b/Misc/ACKS index c39e91c853e9e3a..04401cf87ca6e47 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -419,6 +419,7 @@ Lars Damerow Evan Dandrea Eric Daniel Scott David Daniels +Aaron Davidson Derzsi Dániel Lawrence D'Anna Ben Darnell diff --git a/Misc/NEWS.d/next/Library/2023-03-23-19-47-05.gh-issue-102967.gfIYkN.rst b/Misc/NEWS.d/next/Library/2023-03-23-19-47-05.gh-issue-102967.gfIYkN.rst new file mode 100644 index 000000000000000..677b8ee86e6c8f6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-03-23-19-47-05.gh-issue-102967.gfIYkN.rst @@ -0,0 +1,2 @@ +A bug in :func:`!doctest._SpoofOut.truncate` was causing None to be passed to :func:`!StringIO.seek` when no size was given. +A simple fix skips the seek call when no size is given so the buffer can be truncated from the current position.