From 4d85fcca1dcefc46d1aa9cc9879c09f7d2258537 Mon Sep 17 00:00:00 2001 From: ByteFlow Date: Mon, 27 Apr 2026 12:19:05 +0800 Subject: [PATCH 1/4] Modernize AsyncZip class to use super() and context manager for file handling --- Doc/tutorial/stdlib2.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/tutorial/stdlib2.rst b/Doc/tutorial/stdlib2.rst index 678b71c9274c1c..1e1138f6bf18a4 100644 --- a/Doc/tutorial/stdlib2.rst +++ b/Doc/tutorial/stdlib2.rst @@ -178,14 +178,13 @@ tasks in background while the main program continues to run:: class AsyncZip(threading.Thread): def __init__(self, infile, outfile): - threading.Thread.__init__(self) + super().__init__() self.infile = infile self.outfile = outfile def run(self): - f = zipfile.ZipFile(self.outfile, 'w', zipfile.ZIP_DEFLATED) - f.write(self.infile) - f.close() + with zipfile.ZipFile(self.outfile, 'w', zipfile.ZIP_DEFLATED) as f: + f.write(self.infile) print('Finished background zip of:', self.infile) background = AsyncZip('mydata.txt', 'myarchive.zip') From 5cb1c4699a6dfb0e1a945064fa1ccef9f611e346 Mon Sep 17 00:00:00 2001 From: ByteFlow Date: Mon, 27 Apr 2026 12:22:22 +0800 Subject: [PATCH 2/4] Fix syntax in except clause example in errors.rst --- Doc/tutorial/errors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 3c6edf2c4793ab..b5a16b78507edd 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -123,7 +123,7 @@ Handlers only handle exceptions that occur in the corresponding *try clause*, not in other handlers of the same :keyword:`!try` statement. An *except clause* may name multiple exceptions, for example:: - ... except RuntimeError, TypeError, NameError: + ... except (RuntimeError, TypeError, NameError): ... pass A class in an :keyword:`except` clause matches exceptions which are instances of the From 85dd9d23ea6d2e7a795262fc2a8938c780b01521 Mon Sep 17 00:00:00 2001 From: ByteFlow Date: Mon, 27 Apr 2026 14:07:36 +0800 Subject: [PATCH 3/4] Revert "Fix syntax in except clause example in errors.rst" This reverts commit 5cb1c4699a6dfb0e1a945064fa1ccef9f611e346. --- Doc/tutorial/errors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index b5a16b78507edd..3c6edf2c4793ab 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -123,7 +123,7 @@ Handlers only handle exceptions that occur in the corresponding *try clause*, not in other handlers of the same :keyword:`!try` statement. An *except clause* may name multiple exceptions, for example:: - ... except (RuntimeError, TypeError, NameError): + ... except RuntimeError, TypeError, NameError: ... pass A class in an :keyword:`except` clause matches exceptions which are instances of the From eb2e6e027871c9e18634dc88b1020fe3c1b55c1e Mon Sep 17 00:00:00 2001 From: ByteFlow Date: Mon, 27 Apr 2026 15:31:01 +0800 Subject: [PATCH 4/4] Normalize capitalization in standard library tutorial sections Co-authored-by: Copilot --- Doc/tutorial/stdlib2.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/tutorial/stdlib2.rst b/Doc/tutorial/stdlib2.rst index 1e1138f6bf18a4..6c68ba01081379 100644 --- a/Doc/tutorial/stdlib2.rst +++ b/Doc/tutorial/stdlib2.rst @@ -1,7 +1,7 @@ .. _tut-brieftourtwo: ********************************************** -Brief Tour of the Standard Library --- Part II +Brief tour of the standard library --- part II ********************************************** This second tour covers more advanced modules that support professional @@ -10,7 +10,7 @@ programming needs. These modules rarely occur in small scripts. .. _tut-output-formatting: -Output Formatting +Output formatting ================= The :mod:`reprlib` module provides a version of :func:`repr` customized for @@ -130,7 +130,7 @@ templates for XML files, plain text reports, and HTML web reports. .. _tut-binary-formats: -Working with Binary Data Record Layouts +Working with binary data record layouts ======================================= The :mod:`struct` module provides :func:`~struct.pack` and @@ -244,7 +244,7 @@ application. .. _tut-weak-references: -Weak References +Weak references =============== Python does automatic memory management (reference counting for most objects and @@ -285,7 +285,7 @@ applications include caching objects that are expensive to create:: .. _tut-list-tools: -Tools for Working with Lists +Tools for working with lists ============================ Many data structure needs can be met with the built-in list type. However, @@ -351,7 +351,7 @@ not want to run a full list sort:: .. _tut-decimal-fp: -Decimal Floating-Point Arithmetic +Decimal floating-point arithmetic ================================= The :mod:`decimal` module offers a :class:`~decimal.Decimal` datatype for