]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
*: Use dict comprehensions where applicable
authorBen Darnell <ben@bendarnell.com>
Thu, 13 Jun 2024 18:03:12 +0000 (14:03 -0400)
committerBen Darnell <ben@bendarnell.com>
Thu, 13 Jun 2024 18:03:12 +0000 (14:03 -0400)
Another feature that's been around since Python 2.7
Automated change with modified pyupgrade and black.

tornado/auth.py
tornado/escape.py
tornado/gen.py
tornado/options.py
tornado/routing.py
tornado/web.py

index e19912c9c09f4a3a97640d7fb5e0bced70961878..34bc8f032ae5f1314419bbdb35309080ccb6271e 100644 (file)
@@ -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:
index 84abfca604f28930afdf91e8f8492abd0622914c..023ee16af489a29fc4cefccf83aa6327f451a2bd 100644 (file)
@@ -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):
index 1eb5e7984432acee66bd3274c5f3e5328a95b933..c824c9ff6660b449ab1045ede9e709141cd09cea 100644 (file)
@@ -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]
index fe3644ef3e35eb13137c5147896d81726530caeb..d02a730c6ab3b62b17ac2b65c78a2f09aa9b24da 100644 (file)
@@ -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,
index 607e9f1d73d60a66b2f37d0f5418b04bcd3738e7..324818ebc4168464b6cc107883bd7c5e014c1055 100644 (file)
@@ -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()]
 
index 4bcfb45d2d7cac25916f7549ea9cb993dabdfcb5..aa64145ecd92a99a0d64332a9490658220778ae0 100644 (file)
@@ -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)