From e4da2e3b7e81102d450379b46c924f606c650ebc Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 5 Dec 2025 14:11:21 +0100 Subject: [PATCH 1/3] Fix pyflakes warnings: variable is assigned to but never used Example of fixed warning: Lib/functools.py:690:21: local variable 'oldresult' is assigned to but never used --- Lib/_py_warnings.py | 1 - Lib/_threading_local.py | 2 +- Lib/asyncio/base_events.py | 4 ++-- Lib/asyncio/proactor_events.py | 2 +- Lib/asyncio/tools.py | 2 +- Lib/asyncio/unix_events.py | 2 +- Lib/codeop.py | 4 ++-- Lib/compileall.py | 2 +- Lib/concurrent/interpreters/_queues.py | 6 +++--- Lib/dis.py | 1 - Lib/encodings/uu_codec.py | 2 +- Lib/ftplib.py | 8 ++++---- Lib/functools.py | 1 - Lib/idlelib/pyshell.py | 1 - Lib/idlelib/textview.py | 4 ++-- Lib/imaplib.py | 5 ++--- Lib/inspect.py | 1 - Lib/modulefinder.py | 1 - Lib/multiprocessing/connection.py | 3 +-- Lib/netrc.py | 2 +- Lib/ntpath.py | 2 +- Lib/optparse.py | 2 +- Lib/pickle.py | 5 ++--- Lib/platform.py | 3 +-- Lib/pyclbr.py | 1 - Lib/re/_parser.py | 1 - Lib/subprocess.py | 2 +- Lib/tempfile.py | 2 +- Lib/tokenize.py | 2 +- Lib/turtle.py | 4 ++-- Lib/urllib/parse.py | 2 +- Lib/venv/__init__.py | 1 - 32 files changed, 34 insertions(+), 47 deletions(-) diff --git a/Lib/_py_warnings.py b/Lib/_py_warnings.py index 67c74fdd2d0b42..d5a9cec86f3674 100644 --- a/Lib/_py_warnings.py +++ b/Lib/_py_warnings.py @@ -563,7 +563,6 @@ def warn_explicit(message, category, filename, lineno, else: text = message message = category(message) - modules = None key = (text, category, lineno) with _wm._lock: if registry is None: diff --git a/Lib/_threading_local.py b/Lib/_threading_local.py index 0b9e5d3bbf6ef6..2af3885458b54f 100644 --- a/Lib/_threading_local.py +++ b/Lib/_threading_local.py @@ -57,7 +57,7 @@ def thread_deleted(_, idt=idt): # as soon as the OS-level thread ends instead. local = wrlocal() if local is not None: - dct = local.dicts.pop(idt) + local.dicts.pop(idt) wrlocal = ref(self, local_deleted) wrthread = ref(thread, thread_deleted) thread.__dict__[key] = wrlocal diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 8cbb71f708537f..6619c87bcf5b93 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -949,7 +949,7 @@ async def sock_sendfile(self, sock, file, offset=0, count=None, try: return await self._sock_sendfile_native(sock, file, offset, count) - except exceptions.SendfileNotAvailableError as exc: + except exceptions.SendfileNotAvailableError: if not fallback: raise return await self._sock_sendfile_fallback(sock, file, @@ -1270,7 +1270,7 @@ async def sendfile(self, transport, file, offset=0, count=None, try: return await self._sendfile_native(transport, file, offset, count) - except exceptions.SendfileNotAvailableError as exc: + except exceptions.SendfileNotAvailableError: if not fallback: raise diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index f404273c3ae5c1..3fa93b14a6787f 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -733,7 +733,7 @@ async def sock_accept(self, sock): async def _sock_sendfile_native(self, sock, file, offset, count): try: fileno = file.fileno() - except (AttributeError, io.UnsupportedOperation) as err: + except (AttributeError, io.UnsupportedOperation): raise exceptions.SendfileNotAvailableError("not a regular file") try: fsize = os.fstat(fileno).st_size diff --git a/Lib/asyncio/tools.py b/Lib/asyncio/tools.py index 1d463ea09ba5b8..f9b8a4ee56c5c1 100644 --- a/Lib/asyncio/tools.py +++ b/Lib/asyncio/tools.py @@ -244,7 +244,7 @@ def _get_awaited_by_tasks(pid: int) -> list: e = e.__context__ print(f"Error retrieving tasks: {e}") sys.exit(1) - except PermissionError as e: + except PermissionError: exit_with_permission_help_text() diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 1c1458127db5ac..49e8067ee7b4e5 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -359,7 +359,7 @@ async def _sock_sendfile_native(self, sock, file, offset, count): "os.sendfile() is not available") try: fileno = file.fileno() - except (AttributeError, io.UnsupportedOperation) as err: + except (AttributeError, io.UnsupportedOperation): raise exceptions.SendfileNotAvailableError("not a regular file") try: fsize = os.fstat(fileno).st_size diff --git a/Lib/codeop.py b/Lib/codeop.py index 8cac00442d99e3..40e88423119bc4 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -66,9 +66,9 @@ def _maybe_compile(compiler, source, filename, symbol, flags): try: compiler(source + "\n", filename, symbol, flags=flags) return None - except _IncompleteInputError as e: + except _IncompleteInputError: return None - except SyntaxError as e: + except SyntaxError: pass # fallthrough diff --git a/Lib/compileall.py b/Lib/compileall.py index 67fe370451e1ef..9519a5ac16f024 100644 --- a/Lib/compileall.py +++ b/Lib/compileall.py @@ -223,7 +223,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0, cfile = importlib.util.cache_from_source(fullname) opt_cfiles[opt_level] = cfile - head, tail = name[:-3], name[-3:] + tail = name[-3:] if tail == '.py': if not force: try: diff --git a/Lib/concurrent/interpreters/_queues.py b/Lib/concurrent/interpreters/_queues.py index b5cc0b8944940d..ee159d7de63827 100644 --- a/Lib/concurrent/interpreters/_queues.py +++ b/Lib/concurrent/interpreters/_queues.py @@ -223,7 +223,7 @@ def put(self, obj, block=True, timeout=None, *, while True: try: _queues.put(self._id, obj, unboundop) - except QueueFull as exc: + except QueueFull: if timeout is not None and time.time() >= end: raise # re-raise time.sleep(_delay) @@ -258,7 +258,7 @@ def get(self, block=True, timeout=None, *, while True: try: obj, unboundop = _queues.get(self._id) - except QueueEmpty as exc: + except QueueEmpty: if timeout is not None and time.time() >= end: raise # re-raise time.sleep(_delay) @@ -277,7 +277,7 @@ def get_nowait(self): """ try: obj, unboundop = _queues.get(self._id) - except QueueEmpty as exc: + except QueueEmpty: raise # re-raise if unboundop is not None: assert obj is None, repr(obj) diff --git a/Lib/dis.py b/Lib/dis.py index d6d2c1386dd785..8c257d118fb23b 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -530,7 +530,6 @@ def print_instruction_line(self, instr, mark_as_current): fields.append(instr.opname.ljust(_OPNAME_WIDTH)) # Column: Opcode argument if instr.arg is not None: - arg = repr(instr.arg) # If opname is longer than _OPNAME_WIDTH, we allow it to overflow into # the space reserved for oparg. This results in fewer misaligned opargs # in the disassembly output. diff --git a/Lib/encodings/uu_codec.py b/Lib/encodings/uu_codec.py index 4e58c62fe9ef0f..4f8704016e2131 100644 --- a/Lib/encodings/uu_codec.py +++ b/Lib/encodings/uu_codec.py @@ -56,7 +56,7 @@ def uu_decode(input, errors='strict'): break try: data = binascii.a2b_uu(s) - except binascii.Error as v: + except binascii.Error: # Workaround for broken uuencoders by /Fredrik Lundh nbytes = (((s[0]-32) & 63) * 4 + 5) // 3 data = binascii.a2b_uu(s[:nbytes]) diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 50771e8c17c250..640acc64f620cc 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -314,9 +314,9 @@ def makeport(self): port = sock.getsockname()[1] # Get proper port host = self.sock.getsockname()[0] # Get proper host if self.af == socket.AF_INET: - resp = self.sendport(host, port) + self.sendport(host, port) else: - resp = self.sendeprt(host, port) + self.sendeprt(host, port) if self.timeout is not _GLOBAL_DEFAULT_TIMEOUT: sock.settimeout(self.timeout) return sock @@ -455,7 +455,7 @@ def retrlines(self, cmd, callback = None): """ if callback is None: callback = print_line - resp = self.sendcmd('TYPE A') + self.sendcmd('TYPE A') with self.transfercmd(cmd) as conn, \ conn.makefile('r', encoding=self.encoding) as fp: while 1: @@ -951,7 +951,7 @@ def test(): elif file[:2] == '-d': cmd = 'CWD' if file[2:]: cmd = cmd + ' ' + file[2:] - resp = ftp.sendcmd(cmd) + ftp.sendcmd(cmd) elif file == '-p': ftp.set_pasv(not ftp.passiveserver) else: diff --git a/Lib/functools.py b/Lib/functools.py index 8063eb5ffc3304..a0774c26c1dafe 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -687,7 +687,6 @@ def wrapper(*args, **kwds): # still adjusting the links. root = oldroot[NEXT] oldkey = root[KEY] - oldresult = root[RESULT] root[KEY] = root[RESULT] = None # Now update the cache dictionary. diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index 1b7c2af1a923d7..b80c8e56c92810 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -498,7 +498,6 @@ def restart_subprocess(self, with_cwd=False, filename=''): self.rpcclt.close() self.terminate_subprocess() console = self.tkconsole - was_executing = console.executing console.executing = False self.spawn_subprocess() try: diff --git a/Lib/idlelib/textview.py b/Lib/idlelib/textview.py index 23f0f4cb5027ec..0f719a06883ad7 100644 --- a/Lib/idlelib/textview.py +++ b/Lib/idlelib/textview.py @@ -129,8 +129,8 @@ def __init__(self, parent, title, contents, modal=True, wrap=WORD, self.title(title) self.viewframe = ViewFrame(self, contents, wrap=wrap) self.protocol("WM_DELETE_WINDOW", self.ok) - self.button_ok = button_ok = Button(self, text='Close', - command=self.ok, takefocus=False) + self.button_ok = Button(self, text='Close', + command=self.ok, takefocus=False) self.viewframe.pack(side='top', expand=True, fill='both') self.is_modal = modal diff --git a/Lib/imaplib.py b/Lib/imaplib.py index c176736548188c..2862ebf73632b9 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -807,7 +807,6 @@ def proxyauth(self, user): (typ, [data]) = .proxyauth(user) """ - name = 'PROXYAUTH' return self._simple_command('PROXYAUTH', user) @@ -1310,7 +1309,7 @@ def _get_tagged_response(self, tag, expect_bye=False): try: self._get_response() - except self.abort as val: + except self.abort: if __debug__: if self.debug >= 1: self.print_log() @@ -1867,7 +1866,7 @@ def Time2Internaldate(date_time): try: optlist, args = getopt.getopt(sys.argv[1:], 'd:s:') - except getopt.error as val: + except getopt.error: optlist, args = (), () stream_command = None diff --git a/Lib/inspect.py b/Lib/inspect.py index 8e7511b3af015f..ff462750888c88 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2140,7 +2140,6 @@ def _signature_strip_non_python_syntax(signature): current_parameter = 0 OP = token.OP - ERRORTOKEN = token.ERRORTOKEN # token stream always starts with ENCODING token, skip it t = next(token_stream) diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py index b115d99ab30ff1..7fb19a5c5d1805 100644 --- a/Lib/modulefinder.py +++ b/Lib/modulefinder.py @@ -400,7 +400,6 @@ def scan_opcodes(self, co): yield "relative_import", (level, fromlist, name) def scan_code(self, co, m): - code = co.co_code scanner = self.scan_opcodes for what, args in scanner(co): if what == "store": diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index fc00d2861260a8..64ec53884aeb5d 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -709,8 +709,7 @@ def accept(self): # written data and then disconnected -- see Issue 14725. else: try: - res = _winapi.WaitForMultipleObjects( - [ov.event], False, INFINITE) + _winapi.WaitForMultipleObjects([ov.event], False, INFINITE) except: ov.cancel() _winapi.CloseHandle(handle) diff --git a/Lib/netrc.py b/Lib/netrc.py index 2f502c1d53364f..750b5071e3c65f 100644 --- a/Lib/netrc.py +++ b/Lib/netrc.py @@ -95,7 +95,7 @@ def _parse(self, file, fp, default_netrc): while 1: # Look for a machine, default, or macdef top-level keyword saved_lineno = lexer.lineno - toplevel = tt = lexer.get_token() + tt = lexer.get_token() if not tt: break elif tt[0] == '#': diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 77d2bf86a5f09d..7d637325240f1c 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -726,7 +726,7 @@ def realpath(path, /, *, strict=False): try: if _getfinalpathname(spath) == path: path = spath - except ValueError as ex: + except ValueError: # Unexpected, as an invalid path should not have gained a prefix # at any point, but we ignore this error just in case. pass diff --git a/Lib/optparse.py b/Lib/optparse.py index 02ff7140882ed6..5ff7f74754f9c1 100644 --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -1372,7 +1372,7 @@ def parse_args(self, args=None, values=None): self.values = values try: - stop = self._process_args(largs, rargs, values) + self._process_args(largs, rargs, values) except (BadOptionError, OptionValueError) as err: self.error(str(err)) diff --git a/Lib/pickle.py b/Lib/pickle.py index 729c215514ad24..eeba26943b3ed4 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -1152,7 +1152,6 @@ def save_frozenset(self, obj): def save_global(self, obj, name=None): write = self.write - memo = self.memo if name is None: name = getattr(obj, '__qualname__', None) @@ -1734,7 +1733,7 @@ def load_binget(self): i = self.read(1)[0] try: self.append(self.memo[i]) - except KeyError as exc: + except KeyError: msg = f'Memo value not found at index {i}' raise UnpicklingError(msg) from None dispatch[BINGET[0]] = load_binget @@ -1743,7 +1742,7 @@ def load_long_binget(self): i, = unpack(' Date: Fri, 5 Dec 2025 21:37:48 +0100 Subject: [PATCH 2/3] Change imaplib code --- Lib/imaplib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 2862ebf73632b9..22a0afcd981519 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -807,7 +807,8 @@ def proxyauth(self, user): (typ, [data]) = .proxyauth(user) """ - return self._simple_command('PROXYAUTH', user) + name = 'PROXYAUTH' + return self._simple_command(name, user) def rename(self, oldmailbox, newmailbox): From ec361e3549d8d5adb64ae77bf6c60d7b327df285 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 6 Dec 2025 11:57:11 +0100 Subject: [PATCH 3/3] Restore functools --- Lib/functools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/functools.py b/Lib/functools.py index a0774c26c1dafe..836eb680ccd4d4 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -687,6 +687,7 @@ def wrapper(*args, **kwds): # still adjusting the links. root = oldroot[NEXT] oldkey = root[KEY] + oldresult = root[RESULT] # noqa: F841 root[KEY] = root[RESULT] = None # Now update the cache dictionary.