From: Ben Darnell Date: Thu, 13 Jun 2024 18:03:12 +0000 (-0400) Subject: *: Use dict comprehensions where applicable X-Git-Tag: v6.5.0b1~47^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9f0a7fdd0b9c13cef0d5cd1f828d5370b66324c6;p=thirdparty%2Ftornado.git *: Use dict comprehensions where applicable Another feature that's been around since Python 2.7 Automated change with modified pyupgrade and black. --- diff --git a/tornado/auth.py b/tornado/auth.py index e19912c9..34bc8f03 100644 --- a/tornado/auth.py +++ b/tornado/auth.py @@ -147,9 +147,9 @@ class OpenIdMixin: """ handler = cast(RequestHandler, self) # Verify the OpenID response via direct request to the OP - args = dict( - (k, v[-1]) for k, v in handler.request.arguments.items() - ) # type: Dict[str, Union[str, bytes]] + args = { + k: v[-1] for k, v in handler.request.arguments.items() + } # type: Dict[str, Union[str, bytes]] args["openid.mode"] = "check_authentication" url = self._OPENID_ENDPOINT # type: ignore if http_client is None: diff --git a/tornado/escape.py b/tornado/escape.py index 84abfca6..023ee16a 100644 --- a/tornado/escape.py +++ b/tornado/escape.py @@ -271,9 +271,7 @@ def recursive_unicode(obj: Any) -> Any: Supports lists, tuples, and dictionaries. """ if isinstance(obj, dict): - return dict( - (recursive_unicode(k), recursive_unicode(v)) for (k, v) in obj.items() - ) + return {recursive_unicode(k): recursive_unicode(v) for (k, v) in obj.items()} elif isinstance(obj, list): return list(recursive_unicode(i) for i in obj) elif isinstance(obj, tuple): diff --git a/tornado/gen.py b/tornado/gen.py index 1eb5e798..c824c9ff 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -362,10 +362,10 @@ class WaitIterator: raise ValueError("You must provide args or kwargs, not both") if kwargs: - self._unfinished = dict((f, k) for (k, f) in kwargs.items()) + self._unfinished = {f: k for (k, f) in kwargs.items()} futures = list(kwargs.values()) # type: Sequence[Future] else: - self._unfinished = dict((f, i) for (i, f) in enumerate(args)) + self._unfinished = {f: i for (i, f) in enumerate(args)} futures = args self._finished = collections.deque() # type: Deque[Future] diff --git a/tornado/options.py b/tornado/options.py index fe3644ef..d02a730c 100644 --- a/tornado/options.py +++ b/tornado/options.py @@ -207,18 +207,18 @@ class OptionParser: .. versionadded:: 3.1 """ - return dict( - (opt.name, opt.value()) + return { + opt.name: opt.value() for name, opt in self._options.items() if not group or group == opt.group_name - ) + } def as_dict(self) -> Dict[str, Any]: """The names and values of all options. .. versionadded:: 3.1 """ - return dict((opt.name, opt.value()) for name, opt in self._options.items()) + return {opt.name: opt.value() for name, opt in self._options.items()} def define( self, diff --git a/tornado/routing.py b/tornado/routing.py index 607e9f1d..324818eb 100644 --- a/tornado/routing.py +++ b/tornado/routing.py @@ -582,9 +582,9 @@ class PathMatches(Matcher): # unnamed groups, we want to use either groups # or groupdict but not both. if self.regex.groupindex: - path_kwargs = dict( - (str(k), _unquote_or_none(v)) for (k, v) in match.groupdict().items() - ) + path_kwargs = { + str(k): _unquote_or_none(v) for (k, v) in match.groupdict().items() + } else: path_args = [_unquote_or_none(s) for s in match.groups()] diff --git a/tornado/web.py b/tornado/web.py index 4bcfb45d..aa64145e 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1788,9 +1788,9 @@ class RequestHandler: if self.request.method not in self.SUPPORTED_METHODS: raise HTTPError(405) self.path_args = [self.decode_argument(arg) for arg in args] - self.path_kwargs = dict( - (k, self.decode_argument(v, name=k)) for (k, v) in kwargs.items() - ) + self.path_kwargs = { + k: self.decode_argument(v, name=k) for (k, v) in kwargs.items() + } # If XSRF cookies are turned on, reject form submissions without # the proper cookie if self.request.method not in ( @@ -2275,7 +2275,7 @@ class Application(ReversibleRouter): def _load_ui_methods(self, methods: Any) -> None: if isinstance(methods, types.ModuleType): - self._load_ui_methods(dict((n, getattr(methods, n)) for n in dir(methods))) + self._load_ui_methods({n: getattr(methods, n) for n in dir(methods)}) elif isinstance(methods, list): for m in methods: self._load_ui_methods(m) @@ -2290,7 +2290,7 @@ class Application(ReversibleRouter): def _load_ui_modules(self, modules: Any) -> None: if isinstance(modules, types.ModuleType): - self._load_ui_modules(dict((n, getattr(modules, n)) for n in dir(modules))) + self._load_ui_modules({n: getattr(modules, n) for n in dir(modules)}) elif isinstance(modules, list): for m in modules: self._load_ui_modules(m)