Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da08470

Browse files
bpo-36431: Use PEP 448 dict unpacking for merging two dicts. (GH-12553)
1 parent 384b81d commit da08470

6 files changed

Lines changed: 14 additions & 29 deletions

File tree

Lib/functools.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ def __new__(*args, **keywords):
285285

286286
if hasattr(func, "func"):
287287
args = func.args + args
288-
tmpkw = func.keywords.copy()
289-
tmpkw.update(keywords)
290-
keywords = tmpkw
291-
del tmpkw
288+
keywords = {**func.keywords, **keywords}
292289
func = func.func
293290

294291
self = super(partial, cls).__new__(cls)
@@ -302,9 +299,8 @@ def __call__(*args, **keywords):
302299
if not args:
303300
raise TypeError("descriptor '__call__' of partial needs an argument")
304301
self, *args = args
305-
newkeywords = self.keywords.copy()
306-
newkeywords.update(keywords)
307-
return self.func(*self.args, *args, **newkeywords)
302+
keywords = {**self.keywords, **keywords}
303+
return self.func(*self.args, *args, **keywords)
308304

309305
@recursive_repr()
310306
def __repr__(self):
@@ -371,8 +367,7 @@ def __init__(self, func, *args, **keywords):
371367
# it's also more efficient since only one function will be called
372368
self.func = func.func
373369
self.args = func.args + args
374-
self.keywords = func.keywords.copy()
375-
self.keywords.update(keywords)
370+
self.keywords = {**func.keywords, **keywords}
376371
else:
377372
self.func = func
378373
self.args = args
@@ -391,11 +386,9 @@ def __repr__(self):
391386

392387
def _make_unbound_method(self):
393388
def _method(*args, **keywords):
394-
call_keywords = self.keywords.copy()
395-
call_keywords.update(keywords)
396-
cls_or_self, *rest = args
397-
call_args = (cls_or_self,) + self.args + tuple(rest)
398-
return self.func(*call_args, **call_keywords)
389+
cls_or_self, *args = args
390+
keywords = {**self.keywords, **keywords}
391+
return self.func(cls_or_self, *self.args, *args, **keywords)
399392
_method.__isabstractmethod__ = self.__isabstractmethod__
400393
_method._partialmethod = self
401394
return _method

Lib/idlelib/rpc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ def dumps(obj, protocol=None):
6464

6565

6666
class CodePickler(pickle.Pickler):
67-
dispatch_table = {types.CodeType: pickle_code}
68-
dispatch_table.update(copyreg.dispatch_table)
67+
dispatch_table = {types.CodeType: pickle_code, **copyreg.dispatch_table}
6968

7069

7170
BUFSIZE = 8*1024

Lib/pdb.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ def _complete_expression(self, text, line, begidx, endidx):
491491
# Collect globals and locals. It is usually not really sensible to also
492492
# complete builtins, and they clutter the namespace quite heavily, so we
493493
# leave them out.
494-
ns = self.curframe.f_globals.copy()
495-
ns.update(self.curframe_locals)
494+
ns = {**self.curframe.f_globals, **self.curframe_locals}
496495
if '.' in text:
497496
# Walk an attribute chain up to the last part, similar to what
498497
# rlcompleter does. This will bail if any of the parts are not
@@ -1377,8 +1376,7 @@ def do_interact(self, arg):
13771376
Start an interactive interpreter whose global namespace
13781377
contains all the (global and local) names found in the current scope.
13791378
"""
1380-
ns = self.curframe.f_globals.copy()
1381-
ns.update(self.curframe_locals)
1379+
ns = {**self.curframe.f_globals, **self.curframe_locals}
13821380
code.interact("*interactive*", local=ns)
13831381

13841382
def do_alias(self, arg):

Lib/urllib/request.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,7 @@ def remove_header(self, header_name):
426426
self.unredirected_hdrs.pop(header_name, None)
427427

428428
def header_items(self):
429-
hdrs = self.unredirected_hdrs.copy()
430-
hdrs.update(self.headers)
429+
hdrs = {**self.unredirected_hdrs, **self.headers}
431430
return list(hdrs.items())
432431

433432
class OpenerDirector:

Lib/xml/etree/ElementTree.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,8 @@ def __init__(self, tag, attrib={}, **extra):
169169
if not isinstance(attrib, dict):
170170
raise TypeError("attrib must be dict, not %s" % (
171171
attrib.__class__.__name__,))
172-
attrib = attrib.copy()
173-
attrib.update(extra)
174172
self.tag = tag
175-
self.attrib = attrib
173+
self.attrib = {**attrib, **extra}
176174
self._children = []
177175

178176
def __repr__(self):
@@ -451,8 +449,7 @@ def SubElement(parent, tag, attrib={}, **extra):
451449
additional attributes given as keyword arguments.
452450
453451
"""
454-
attrib = attrib.copy()
455-
attrib.update(extra)
452+
attrib = {**attrib, **extra}
456453
element = parent.makeelement(tag, attrib)
457454
parent.append(element)
458455
return element

Lib/xml/sax/saxutils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def quoteattr(data, entities={}):
5656
the optional entities parameter. The keys and values must all be
5757
strings; each key will be replaced with its corresponding value.
5858
"""
59-
entities = entities.copy()
60-
entities.update({'\n': '
', '\r': '
', '\t':'	'})
59+
entities = {**entities, '\n': '
', '\r': '
', '\t':'	'}
6160
data = escape(data, entities)
6261
if '"' in data:
6362
if "'" in data:

0 commit comments

Comments
 (0)