From d0331418ef7c9278342ee54f4c625fe29fa8216a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 7 Jul 2017 22:20:41 +0300 Subject: [PATCH 1/2] bpo-30296: Partially revert #1489. --- Lib/email/headerregistry.py | 4 ++-- Lib/inspect.py | 2 +- Lib/logging/config.py | 4 ++-- Lib/pathlib.py | 3 ++- Lib/pstats.py | 2 +- Lib/symtable.py | 4 ++-- Lib/turtle.py | 6 +++--- Lib/urllib/request.py | 3 ++- Tools/gdb/libpython.py | 4 ++-- 9 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Lib/email/headerregistry.py b/Lib/email/headerregistry.py index 81fee146dcc3575..0fc2231e5cbd294 100644 --- a/Lib/email/headerregistry.py +++ b/Lib/email/headerregistry.py @@ -369,8 +369,8 @@ def groups(self): @property def addresses(self): if self._addresses is None: - self._addresses = tuple(address for group in self._groups - for address in group.addresses) + self._addresses = tuple([address for group in self._groups + for address in group.addresses]) return self._addresses diff --git a/Lib/inspect.py b/Lib/inspect.py index 9a843d6420e2e09..e9c2dbd5c88d995 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -389,7 +389,7 @@ def classify_class_attrs(cls): mro = getmro(cls) metamro = getmro(type(cls)) # for attributes stored in the metaclass - metamro = tuple(cls for cls in metamro if cls not in (type, object)) + metamro = tuple([cls for cls in metamro if cls not in (type, object)]) class_bases = (cls,) + mro all_bases = class_bases + metamro names = dir(cls) diff --git a/Lib/logging/config.py b/Lib/logging/config.py index d692514adfef5b6..5df571a20472555 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -463,7 +463,7 @@ def configure_custom(self, config): c = self.resolve(c) props = config.pop('.', None) # Check for valid identifiers - kwargs = dict((k, config[k]) for k in config if valid_ident(k)) + kwargs = {k: config[k] for k in config if valid_ident(k)} result = c(**kwargs) if props: for name, value in props.items(): @@ -726,7 +726,7 @@ def configure_handler(self, config): config['address'] = self.as_tuple(config['address']) factory = klass props = config.pop('.', None) - kwargs = dict((k, config[k]) for k in config if valid_ident(k)) + kwargs = {k: config[k] for k in config if valid_ident(k)} try: result = factory(**kwargs) except TypeError as te: diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 0e65c61f654209c..c17c9e9e3a43fe4 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -114,7 +114,8 @@ class _WindowsFlavour(_Flavour): is_supported = (os.name == 'nt') - drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') + drive_letters = set('abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') ext_namespace_prefix = '\\\\?\\' reserved_names = ( diff --git a/Lib/pstats.py b/Lib/pstats.py index b7a20542a3994be..985aa323433f848 100644 --- a/Lib/pstats.py +++ b/Lib/pstats.py @@ -500,7 +500,7 @@ def add_callers(target, source): if func in new_callers: if isinstance(caller, tuple): # format used by cProfile - new_callers[func] = tuple(i[0] + i[1] for i in zip(caller, new_callers[func])) + new_callers[func] = tuple([i + j for i, j in zip(caller, new_callers[func])]) else: # format used by profile new_callers[func] += caller diff --git a/Lib/symtable.py b/Lib/symtable.py index c7627a6ef68856a..b0e52603dceeb17 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -119,8 +119,8 @@ class Function(SymbolTable): __globals = None def __idents_matching(self, test_func): - return tuple(ident for ident in self.get_identifiers() - if test_func(self._table.symbols[ident])) + return tuple([ident for ident in self.get_identifiers() + if test_func(self._table.symbols[ident])]) def get_parameters(self): if self.__params is None: diff --git a/Lib/turtle.py b/Lib/turtle.py index b2623f16725d5ee..bb878a91050e8df 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -1175,7 +1175,7 @@ def _color(self, cstr): cl = [16*int(cstr[h], 16) for h in cstr[1:]] else: raise TurtleGraphicsError("bad colorstring: %s" % cstr) - return tuple(c * self._colormode/255 for c in cl) + return tuple([c * self._colormode/255 for c in cl]) def colormode(self, cmode=None): """Return the colormode or set it to 1.0 or 255. @@ -2989,7 +2989,7 @@ def _getshapepoly(self, polygon, compound=False): t11, t12, t21, t22 = l, 0, 0, l elif self._resizemode == "noresize": return polygon - return tuple((t11*x + t12*y, t21*x + t22*y) for (x, y) in polygon) + return tuple([(t11*x + t12*y, t21*x + t22*y) for (x, y) in polygon]) def _drawturtle(self): """Manages the correct rendering of the turtle with respect to @@ -3839,7 +3839,7 @@ def write_docstringdict(filename="turtle_docstringdict"): docsdict[key] = eval(key).__doc__ with open("%s.py" % filename,"w") as f: - keys = sorted(x for x in docsdict.keys() + keys = sorted(x for x in docsdict if x.split('.')[1] not in _alias_list) f.write('docsdict = {\n\n') for key in keys[:-1]: diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index a192d527d8bc9a4..cf91d0b7e99f812 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1286,7 +1286,8 @@ def do_open(self, http_class, req, **http_conn_args): h.set_debuglevel(self._debuglevel) headers = dict(req.unredirected_hdrs) - headers.update((k, v) for k, v in req.headers.items() if k not in headers) + headers.update({k: v for k, v in req.headers.items() + if k not in headers}) # TODO(jhylton): Should this be redesigned to handle # persistent connections? diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index cc23b8402df9d55..0e9df2bd52f1f4f 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -1097,8 +1097,8 @@ def proxyval(self, visited): return ProxyAlreadyVisited('(...)') visited.add(self.as_address()) - result = tuple(PyObjectPtr.from_pyobject_ptr(self[i]).proxyval(visited) - for i in safe_range(int_from_int(self.field('ob_size')))) + result = tuple([PyObjectPtr.from_pyobject_ptr(self[i]).proxyval(visited) + for i in safe_range(int_from_int(self.field('ob_size')))]) return result def write_repr(self, out, visited): From becbbd6ed333076f6ab3280fd317a19de75a5a61 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 26 Feb 2018 16:16:19 +0200 Subject: [PATCH 2/2] Keep generator expressions for creating tuples. --- Lib/email/headerregistry.py | 4 ++-- Lib/inspect.py | 2 +- Lib/pathlib.py | 3 +-- Lib/pstats.py | 2 +- Lib/symtable.py | 4 ++-- Lib/turtle.py | 4 ++-- Tools/gdb/libpython.py | 4 ++-- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Lib/email/headerregistry.py b/Lib/email/headerregistry.py index f5be87f4d24368e..00652049f2fa2fc 100644 --- a/Lib/email/headerregistry.py +++ b/Lib/email/headerregistry.py @@ -372,8 +372,8 @@ def groups(self): @property def addresses(self): if self._addresses is None: - self._addresses = tuple([address for group in self._groups - for address in group.addresses]) + self._addresses = tuple(address for group in self._groups + for address in group.addresses) return self._addresses diff --git a/Lib/inspect.py b/Lib/inspect.py index f9bab97beec0db0..109efc06b268690 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -388,7 +388,7 @@ def classify_class_attrs(cls): mro = getmro(cls) metamro = getmro(type(cls)) # for attributes stored in the metaclass - metamro = tuple([cls for cls in metamro if cls not in (type, object)]) + metamro = tuple(cls for cls in metamro if cls not in (type, object)) class_bases = (cls,) + mro all_bases = class_bases + metamro names = dir(cls) diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 7c45f528d2959e8..8431c29c1d6516f 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -114,8 +114,7 @@ class _WindowsFlavour(_Flavour): is_supported = (os.name == 'nt') - drive_letters = set('abcdefghijklmnopqrstuvwxyz' - 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') + drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') ext_namespace_prefix = '\\\\?\\' reserved_names = ( diff --git a/Lib/pstats.py b/Lib/pstats.py index 098eaa9aebd7034..ded5ae59f7da21f 100644 --- a/Lib/pstats.py +++ b/Lib/pstats.py @@ -530,7 +530,7 @@ def add_callers(target, source): if func in new_callers: if isinstance(caller, tuple): # format used by cProfile - new_callers[func] = tuple([i + j for i, j in zip(caller, new_callers[func])]) + new_callers[func] = tuple(i + j for i, j in zip(caller, new_callers[func])) else: # format used by profile new_callers[func] += caller diff --git a/Lib/symtable.py b/Lib/symtable.py index b0e52603dceeb17..c7627a6ef68856a 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -119,8 +119,8 @@ class Function(SymbolTable): __globals = None def __idents_matching(self, test_func): - return tuple([ident for ident in self.get_identifiers() - if test_func(self._table.symbols[ident])]) + return tuple(ident for ident in self.get_identifiers() + if test_func(self._table.symbols[ident])) def get_parameters(self): if self.__params is None: diff --git a/Lib/turtle.py b/Lib/turtle.py index 57b21a7a9beba91..9db564b7eb8bd40 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -1175,7 +1175,7 @@ def _color(self, cstr): cl = [16*int(cstr[h], 16) for h in cstr[1:]] else: raise TurtleGraphicsError("bad colorstring: %s" % cstr) - return tuple([c * self._colormode/255 for c in cl]) + return tuple(c * self._colormode/255 for c in cl) def colormode(self, cmode=None): """Return the colormode or set it to 1.0 or 255. @@ -2989,7 +2989,7 @@ def _getshapepoly(self, polygon, compound=False): t11, t12, t21, t22 = l, 0, 0, l elif self._resizemode == "noresize": return polygon - return tuple([(t11*x + t12*y, t21*x + t22*y) for (x, y) in polygon]) + return tuple((t11*x + t12*y, t21*x + t22*y) for (x, y) in polygon) def _drawturtle(self): """Manages the correct rendering of the turtle with respect to diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index b31be9419b3379e..839ce799797e72a 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -1099,8 +1099,8 @@ def proxyval(self, visited): return ProxyAlreadyVisited('(...)') visited.add(self.as_address()) - result = tuple([PyObjectPtr.from_pyobject_ptr(self[i]).proxyval(visited) - for i in safe_range(int_from_int(self.field('ob_size')))]) + result = tuple(PyObjectPtr.from_pyobject_ptr(self[i]).proxyval(visited) + for i in safe_range(int_from_int(self.field('ob_size')))) return result def write_repr(self, out, visited):