From d95bf7c96e54cf42a68e30aa4f4bd4d8ec5b0945 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Sat, 19 Jul 2025 12:57:10 +0000 Subject: [PATCH] Refactor simple dict.update calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit refactors simple `dict.update({key: value})` calls which can be done via `dict[key] = value` instead. I found those cases with the [semgrep](https://semgrep.dev/) tool: ``` $ semgrep --lang python --pattern '$DICT.update({$A: ...})' ┌─────────────────┐ │ 5 Code Findings │ └─────────────────┘ Lib/dataclasses.py 1268┆ slots.update({slot: doc}) Lib/multiprocessing/resource_tracker.py 50┆ _CLEANUP_FUNCS.update({ 51┆ 'semaphore': _multiprocessing.sem_unlink, 52┆ }) ⋮┆---------------------------------------- 53┆ _CLEANUP_FUNCS.update({ 54┆ 'shared_memory': _posixshmem.shm_unlink, 55┆ }) Lib/tkinter/scrolledtext.py 26┆ kw.update({'yscrollcommand': self.vbar.set}) Lib/xmlrpc/server.py 242┆ self.funcs.update({'system.multicall' : self.system_multicall}) ``` --- Lib/dataclasses.py | 2 +- Lib/multiprocessing/resource_tracker.py | 8 ++------ Lib/tkinter/scrolledtext.py | 2 +- Lib/xmlrpc/server.py | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py index 86d29df0639184..83ea623dce6281 100644 --- a/Lib/dataclasses.py +++ b/Lib/dataclasses.py @@ -1265,7 +1265,7 @@ def _create_slots(defined_fields, inherited_slots, field_names, weakref_slot): doc = getattr(defined_fields.get(slot), 'doc', None) if doc is not None: seen_docs = True - slots.update({slot: doc}) + slots[slot] = doc # We only return dict if there's at least one doc member, # otherwise we return tuple, which is the old default format. diff --git a/Lib/multiprocessing/resource_tracker.py b/Lib/multiprocessing/resource_tracker.py index 05633ac21a259c..c4d0ca81e7034a 100644 --- a/Lib/multiprocessing/resource_tracker.py +++ b/Lib/multiprocessing/resource_tracker.py @@ -47,12 +47,8 @@ def cleanup_noop(name): # absence of POSIX named semaphores. In that case, no named semaphores were # ever opened, so no cleanup would be necessary. if hasattr(_multiprocessing, 'sem_unlink'): - _CLEANUP_FUNCS.update({ - 'semaphore': _multiprocessing.sem_unlink, - }) - _CLEANUP_FUNCS.update({ - 'shared_memory': _posixshmem.shm_unlink, - }) + _CLEANUP_FUNCS['semaphore'] = _multiprocessing.sem_unlink + _CLEANUP_FUNCS['shared_memory'] = _posixshmem.shm_unlink class ReentrantCallError(RuntimeError): diff --git a/Lib/tkinter/scrolledtext.py b/Lib/tkinter/scrolledtext.py index 4f9a8815b6184b..8dcead5e31930e 100644 --- a/Lib/tkinter/scrolledtext.py +++ b/Lib/tkinter/scrolledtext.py @@ -23,7 +23,7 @@ def __init__(self, master=None, **kw): self.vbar = Scrollbar(self.frame) self.vbar.pack(side=RIGHT, fill=Y) - kw.update({'yscrollcommand': self.vbar.set}) + kw['yscrollcommand'] = self.vbar.set Text.__init__(self, self.frame, **kw) self.pack(side=LEFT, fill=BOTH, expand=True) self.vbar['command'] = self.yview diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py index 8130c739af2fe8..3e6871157d0929 100644 --- a/Lib/xmlrpc/server.py +++ b/Lib/xmlrpc/server.py @@ -239,7 +239,7 @@ def register_multicall_functions(self): see http://www.xmlrpc.com/discuss/msgReader$1208""" - self.funcs.update({'system.multicall' : self.system_multicall}) + self.funcs['system.multicall'] = self.system_multicall def _marshaled_dispatch(self, data, dispatch_method = None, path = None): """Dispatches an XML-RPC method from marshalled (XML) data. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy