]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
web,template: Work around test failures on pypy3
authorBen Darnell <ben@bendarnell.com>
Sun, 7 Oct 2018 15:42:49 +0000 (11:42 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 7 Oct 2018 16:14:45 +0000 (12:14 -0400)
pypy3 doesn't yet have the typing.ContextManager type, and
https://bitbucket.org/pypy/pypy/issues/2868/segfault-with-args-type-annotation-in

tornado/template.py
tornado/web.py

index 4ef65beac9c1340719ecf566c40cc19a6e406c44..1433dfae6a77956585f7457e26315fecfb6624a9 100644 (file)
@@ -207,21 +207,11 @@ from tornado import escape
 from tornado.log import app_log
 from tornado.util import ObjectDict, exec_in, unicode_type
 
-from typing import (
-    Any,
-    Union,
-    Callable,
-    List,
-    Dict,
-    Iterable,
-    Optional,
-    TextIO,
-    ContextManager,
-)
+from typing import Any, Union, Callable, List, Dict, Iterable, Optional, TextIO
 import typing
 
 if typing.TYPE_CHECKING:
-    from typing import Tuple  # noqa: F401
+    from typing import Tuple, ContextManager  # noqa: F401
 
 _DEFAULT_AUTOESCAPE = "xhtml_escape"
 
@@ -747,7 +737,7 @@ class _CodeWriter(object):
     def indent_size(self) -> int:
         return self._indent
 
-    def indent(self) -> ContextManager:
+    def indent(self) -> "ContextManager":
         class Indenter(object):
             def __enter__(_) -> "_CodeWriter":
                 self._indent += 1
@@ -759,7 +749,7 @@ class _CodeWriter(object):
 
         return Indenter()
 
-    def include(self, template: Template, line: int) -> ContextManager:
+    def include(self, template: Template, line: int) -> "ContextManager":
         self.include_stack.append((self.current_template, line))
         self.current_template = template
 
index 9742b88a6e520ed3b6dd803b2d2c77787e494f7c..a9d28a600afb4f790b1cc01fbc56294c509f587e 100644 (file)
@@ -1795,7 +1795,7 @@ class RequestHandler(object):
             )
 
     def _ui_module(self, name: str, module: Type["UIModule"]) -> Callable[..., str]:
-        def render(*args: Any, **kwargs: Any) -> str:
+        def render(*args, **kwargs) -> str:  # type: ignore
             if not hasattr(self, "_active_modules"):
                 self._active_modules = {}  # type: Dict[str, UIModule]
             if name not in self._active_modules:
@@ -1871,8 +1871,8 @@ def removeslash(
     """
 
     @functools.wraps(method)
-    def wrapper(
-        self: RequestHandler, *args: Any, **kwargs: Any
+    def wrapper(  # type: ignore
+        self: RequestHandler, *args, **kwargs
     ) -> Optional[Awaitable[None]]:
         if self.request.path.endswith("/"):
             if self.request.method in ("GET", "HEAD"):
@@ -1900,8 +1900,8 @@ def addslash(
     """
 
     @functools.wraps(method)
-    def wrapper(
-        self: RequestHandler, *args: Any, **kwargs: Any
+    def wrapper(  # type: ignore
+        self: RequestHandler, *args, **kwargs
     ) -> Optional[Awaitable[None]]:
         if not self.request.path.endswith("/"):
             if self.request.method in ("GET", "HEAD"):
@@ -3150,8 +3150,8 @@ def authenticated(
     """
 
     @functools.wraps(method)
-    def wrapper(
-        self: RequestHandler, *args: Any, **kwargs: Any
+    def wrapper(  # type: ignore
+        self: RequestHandler, *args, **kwargs
     ) -> Optional[Awaitable[None]]:
         if not self.current_user:
             if self.request.method in ("GET", "HEAD"):
@@ -3272,7 +3272,7 @@ class TemplateModule(UIModule):
         self._resource_dict = {}  # type: Dict[str, Dict[str, Any]]
 
     def render(self, path: str, **kwargs: Any) -> bytes:  # type: ignore
-        def set_resources(**kwargs: Any) -> str:
+        def set_resources(**kwargs) -> str:  # type: ignore
             if path not in self._resource_dict:
                 self._resource_list.append(kwargs)
                 self._resource_dict[path] = kwargs