bpo-36431: Use PEP 448 dict unpacking for merging two dicts. (GH-12553)

This commit is contained in:
Serhiy Storchaka 2019-03-27 08:02:28 +02:00 committed by GitHub
parent 384b81d923
commit da0847048a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 29 deletions

View File

@ -285,10 +285,7 @@ class partial:
if hasattr(func, "func"): if hasattr(func, "func"):
args = func.args + args args = func.args + args
tmpkw = func.keywords.copy() keywords = {**func.keywords, **keywords}
tmpkw.update(keywords)
keywords = tmpkw
del tmpkw
func = func.func func = func.func
self = super(partial, cls).__new__(cls) self = super(partial, cls).__new__(cls)
@ -302,9 +299,8 @@ class partial:
if not args: if not args:
raise TypeError("descriptor '__call__' of partial needs an argument") raise TypeError("descriptor '__call__' of partial needs an argument")
self, *args = args self, *args = args
newkeywords = self.keywords.copy() keywords = {**self.keywords, **keywords}
newkeywords.update(keywords) return self.func(*self.args, *args, **keywords)
return self.func(*self.args, *args, **newkeywords)
@recursive_repr() @recursive_repr()
def __repr__(self): def __repr__(self):
@ -371,8 +367,7 @@ class partialmethod(object):
# it's also more efficient since only one function will be called # it's also more efficient since only one function will be called
self.func = func.func self.func = func.func
self.args = func.args + args self.args = func.args + args
self.keywords = func.keywords.copy() self.keywords = {**func.keywords, **keywords}
self.keywords.update(keywords)
else: else:
self.func = func self.func = func
self.args = args self.args = args
@ -391,11 +386,9 @@ class partialmethod(object):
def _make_unbound_method(self): def _make_unbound_method(self):
def _method(*args, **keywords): def _method(*args, **keywords):
call_keywords = self.keywords.copy() cls_or_self, *args = args
call_keywords.update(keywords) keywords = {**self.keywords, **keywords}
cls_or_self, *rest = args return self.func(cls_or_self, *self.args, *args, **keywords)
call_args = (cls_or_self,) + self.args + tuple(rest)
return self.func(*call_args, **call_keywords)
_method.__isabstractmethod__ = self.__isabstractmethod__ _method.__isabstractmethod__ = self.__isabstractmethod__
_method._partialmethod = self _method._partialmethod = self
return _method return _method

View File

@ -64,8 +64,7 @@ def dumps(obj, protocol=None):
class CodePickler(pickle.Pickler): class CodePickler(pickle.Pickler):
dispatch_table = {types.CodeType: pickle_code} dispatch_table = {types.CodeType: pickle_code, **copyreg.dispatch_table}
dispatch_table.update(copyreg.dispatch_table)
BUFSIZE = 8*1024 BUFSIZE = 8*1024

View File

@ -491,8 +491,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
# Collect globals and locals. It is usually not really sensible to also # Collect globals and locals. It is usually not really sensible to also
# complete builtins, and they clutter the namespace quite heavily, so we # complete builtins, and they clutter the namespace quite heavily, so we
# leave them out. # leave them out.
ns = self.curframe.f_globals.copy() ns = {**self.curframe.f_globals, **self.curframe_locals}
ns.update(self.curframe_locals)
if '.' in text: if '.' in text:
# Walk an attribute chain up to the last part, similar to what # Walk an attribute chain up to the last part, similar to what
# rlcompleter does. This will bail if any of the parts are not # rlcompleter does. This will bail if any of the parts are not
@ -1377,8 +1376,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
Start an interactive interpreter whose global namespace Start an interactive interpreter whose global namespace
contains all the (global and local) names found in the current scope. contains all the (global and local) names found in the current scope.
""" """
ns = self.curframe.f_globals.copy() ns = {**self.curframe.f_globals, **self.curframe_locals}
ns.update(self.curframe_locals)
code.interact("*interactive*", local=ns) code.interact("*interactive*", local=ns)
def do_alias(self, arg): def do_alias(self, arg):

View File

@ -426,8 +426,7 @@ class Request:
self.unredirected_hdrs.pop(header_name, None) self.unredirected_hdrs.pop(header_name, None)
def header_items(self): def header_items(self):
hdrs = self.unredirected_hdrs.copy() hdrs = {**self.unredirected_hdrs, **self.headers}
hdrs.update(self.headers)
return list(hdrs.items()) return list(hdrs.items())
class OpenerDirector: class OpenerDirector:

View File

@ -169,10 +169,8 @@ class Element:
if not isinstance(attrib, dict): if not isinstance(attrib, dict):
raise TypeError("attrib must be dict, not %s" % ( raise TypeError("attrib must be dict, not %s" % (
attrib.__class__.__name__,)) attrib.__class__.__name__,))
attrib = attrib.copy()
attrib.update(extra)
self.tag = tag self.tag = tag
self.attrib = attrib self.attrib = {**attrib, **extra}
self._children = [] self._children = []
def __repr__(self): def __repr__(self):
@ -451,8 +449,7 @@ def SubElement(parent, tag, attrib={}, **extra):
additional attributes given as keyword arguments. additional attributes given as keyword arguments.
""" """
attrib = attrib.copy() attrib = {**attrib, **extra}
attrib.update(extra)
element = parent.makeelement(tag, attrib) element = parent.makeelement(tag, attrib)
parent.append(element) parent.append(element)
return element return element

View File

@ -56,8 +56,7 @@ def quoteattr(data, entities={}):
the optional entities parameter. The keys and values must all be the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value. strings; each key will be replaced with its corresponding value.
""" """
entities = entities.copy() entities = {**entities, '\n': '
', '\r': '
', '\t':'	'}
entities.update({'\n': '
', '\r': '
', '\t':'	'})
data = escape(data, entities) data = escape(data, entities)
if '"' in data: if '"' in data:
if "'" in data: if "'" in data: