https://github.com/python/cpython/commit/0b8c348f2756c193d6bd2618cadbb90b2f218ccc
commit: 0b8c348f2756c193d6bd2618cadbb90b2f218ccc
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-12-08T14:00:31+01:00
summary:
Fix pyflakes warnings: variable is assigned to but never used (#142294)
Example of fixed warning:
Lib/netrc.py:98:13: local variable 'toplevel'
is assigned to but never used
files:
M Lib/_py_warnings.py
M Lib/_threading_local.py
M Lib/asyncio/base_events.py
M Lib/asyncio/proactor_events.py
M Lib/asyncio/tools.py
M Lib/asyncio/unix_events.py
M Lib/codeop.py
M Lib/compileall.py
M Lib/concurrent/interpreters/_queues.py
M Lib/dis.py
M Lib/encodings/uu_codec.py
M Lib/ftplib.py
M Lib/functools.py
M Lib/idlelib/pyshell.py
M Lib/idlelib/textview.py
M Lib/imaplib.py
M Lib/inspect.py
M Lib/modulefinder.py
M Lib/multiprocessing/connection.py
M Lib/netrc.py
M Lib/ntpath.py
M Lib/optparse.py
M Lib/pickle.py
M Lib/platform.py
M Lib/pyclbr.py
M Lib/re/_parser.py
M Lib/subprocess.py
M Lib/tempfile.py
M Lib/tokenize.py
M Lib/turtle.py
M Lib/urllib/parse.py
M Lib/venv/__init__.py
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..836eb680ccd4d4 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -687,7 +687,7 @@ def wrapper(*args, **kwds):
# still adjusting the links.
root = oldroot[NEXT]
oldkey = root[KEY]
- oldresult = root[RESULT]
+ oldresult = root[RESULT] # noqa: F841
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..22a0afcd981519 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -808,7 +808,7 @@ def proxyauth(self, user):
"""
name = 'PROXYAUTH'
- return self._simple_command('PROXYAUTH', user)
+ return self._simple_command(name, user)
def rename(self, oldmailbox, newmailbox):
@@ -1310,7 +1310,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 +1867,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 f3025776623d2c..71c12c50f7f035 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -1169,7 +1169,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)
@@ -1756,7 +1755,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
@@ -1765,7 +1764,7 @@ def load_long_binget(self):
i, = unpack('<I', self.read(4))
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[LONG_BINGET[0]] = load_long_binget
diff --git a/Lib/platform.py b/Lib/platform.py
index b5017dbdb02252..3a71b669985f13 100644
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -305,8 +305,7 @@ def _syscmd_ver(system='', release='', version='',
text=True,
encoding="locale",
shell=True)
- except (OSError, subprocess.CalledProcessError) as why:
- #print('Command %s failed: %s' % (cmd, why))
+ except (OSError, subprocess.CalledProcessError):
continue
else:
break
diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py
index 37f86995d6ce00..35772cc01d0517 100644
--- a/Lib/pyclbr.py
+++ b/Lib/pyclbr.py
@@ -158,7 +158,6 @@ def _readmodule(module, path, inpackage=None):
return _readmodule(submodule, parent['__path__'], package)
# Search the path for the module.
- f = None
if inpackage is not None:
search_path = path
else:
diff --git a/Lib/re/_parser.py b/Lib/re/_parser.py
index 35ab7ede2a75a9..bd189fe0695f80 100644
--- a/Lib/re/_parser.py
+++ b/Lib/re/_parser.py
@@ -455,7 +455,6 @@ def _parse_sub(source, state, verbose, nested):
items = []
itemsappend = items.append
sourcematch = source.match
- start = source.tell()
while True:
itemsappend(_parse(source, state, verbose, nested + 1,
not nested and not items))
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 4d5ab6fbff0a46..17333d8c02255d 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1235,7 +1235,7 @@ def communicate(self, input=None, timeout=None):
finally:
self._communication_started = True
try:
- sts = self.wait(timeout=self._remaining_time(endtime))
+ self.wait(timeout=self._remaining_time(endtime))
except TimeoutExpired as exc:
exc.timeout = timeout
raise
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 53d14ff5c67131..2bc61662459992 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -691,7 +691,7 @@ def opener(*args):
fd, name = _mkstemp_inner(dir, prefix, suffix, flags, output_type)
try:
_os.unlink(name)
- except BaseException as e:
+ except BaseException:
_os.close(fd)
raise
return fd
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index 1f31258ce361c9..11c134482db024 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -403,7 +403,7 @@ def find_cookie(line):
return None
encoding = _get_normal_name(match.group(1).decode())
try:
- codec = lookup(encoding)
+ lookup(encoding)
except LookupError:
# This behaviour mimics the Python interpreter
if filename is None:
diff --git a/Lib/turtle.py b/Lib/turtle.py
index e5ce2c0a03cad6..b52d681b3af1c3 100644
--- a/Lib/turtle.py
+++ b/Lib/turtle.py
@@ -565,7 +565,7 @@ def _iscolorstring(self, color):
"""Check if the string color is a legal Tkinter color string.
"""
try:
- rgb = self.cv.winfo_rgb(color)
+ self.cv.winfo_rgb(color)
ok = True
except TK.TclError:
ok = False
@@ -3747,7 +3747,7 @@ def _undo(self, action, data):
if action == "rot":
angle, degPAU = data
self._rotate(-angle*degPAU/self._degreesPerAU)
- dummy = self.undobuffer.pop()
+ self.undobuffer.pop()
elif action == "stamp":
stitem = data[0]
self.clearstamp(stitem)
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
index c7946d7625386d..79fd6abaa1c48f 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -1062,7 +1062,7 @@ def urlencode(query, doseq=False, safe='', encoding=None,
errors=None,
else:
try:
# Is this a sufficient test for sequence-ness?
- x = len(v)
+ len(v)
except TypeError:
# not a sequence
v = quote_via(str(v), safe, encoding, errors)
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index e5addcc393a1b9..19eddde700bcf9 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -306,7 +306,6 @@ def setup_python(self, context):
binpath = context.bin_path
path = context.env_exe
copier = self.symlink_or_copy
- dirname = context.python_dir
copier(context.executable, path)
if not os.path.islink(path):
os.chmod(path, 0o755)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]