From: Ben Darnell Date: Sun, 7 Oct 2018 15:42:49 +0000 (-0400) Subject: web,template: Work around test failures on pypy3 X-Git-Tag: v6.0.0b1~28^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=753987b3f192b1375a67fbe1688b70f5ec55396a;p=thirdparty%2Ftornado.git web,template: Work around test failures on pypy3 pypy3 doesn't yet have the typing.ContextManager type, and https://bitbucket.org/pypy/pypy/issues/2868/segfault-with-args-type-annotation-in --- diff --git a/tornado/template.py b/tornado/template.py index 4ef65beac..1433dfae6 100644 --- a/tornado/template.py +++ b/tornado/template.py @@ -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 diff --git a/tornado/web.py b/tornado/web.py index 9742b88a6..a9d28a600 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -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