From 3bb30729afa55f636d31afbaa5155740394de297 Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 24 Mar 2023 04:24:27 +0900 Subject: [PATCH 1/5] bufix for issue-102967 --- Lib/doctest.py | 3 ++- Misc/ACKS | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/doctest.py b/Lib/doctest.py index 2776d74bf9b586..51bdd2f381e848 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -270,7 +270,8 @@ def getvalue(self): return result def truncate(self, size=None): - self.seek(size) + if size != None: + self.seek(size) StringIO.truncate(self) # Worst-case linear-time ellipsis matching. diff --git a/Misc/ACKS b/Misc/ACKS index 8cf5166a2bb1f4..2a1d0181452c7b 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -406,6 +406,7 @@ Lars Damerow Evan Dandrea Eric Daniel Scott David Daniels +Aaron Davidson Derzsi Dániel Lawrence D'Anna Ben Darnell From 8d4e729bf8f80337a40c80f28d256b65b13ffc2a Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 23 Mar 2023 19:47:06 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-03-23-19-47-05.gh-issue-102967.gfIYkN.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-03-23-19-47-05.gh-issue-102967.gfIYkN.rst 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 00000000000000..bcece939531869 --- /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. From 516836def8d26e13cdf2682def052aee1944c718 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 13 Aug 2026 10:11:16 +0300 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Serhiy Storchaka --- Lib/doctest.py | 2 +- .../Library/2023-03-23-19-47-05.gh-issue-102967.gfIYkN.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/doctest.py b/Lib/doctest.py index 2a5f48d93462e5..8248506c37804e 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -285,7 +285,7 @@ def getvalue(self): return result def truncate(self, size=None): - if size != None: + if size is not None: self.seek(size) StringIO.truncate(self) 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 index bcece939531869..e0676163d75316 100644 --- 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 @@ -1,2 +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. +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. From 332690ae09d055cb2377cfeda5d4eb958ff276cb Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 13 Aug 2026 10:16:47 +0300 Subject: [PATCH 4/5] Fix bug in doctest._SpoofOut.truncate method From 09fc43a6854f80790df0dc5b78d062eb00bc2956 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 13 Aug 2026 10:34:42 +0300 Subject: [PATCH 5/5] Fix the line endings in the NEWS entry Co-Authored-By: Claude Opus 5 (1M context) --- .../Library/2023-03-23-19-47-05.gh-issue-102967.gfIYkN.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index e0676163d75316..677b8ee86e6c8f 100644 --- 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 @@ -1,2 +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. +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.