diff --git a/aiohttp_jinja2/__init__.py b/aiohttp_jinja2/__init__.py index c70c528c..1e5f39f0 100644 --- a/aiohttp_jinja2/__init__.py +++ b/aiohttp_jinja2/__init__.py @@ -1,6 +1,5 @@ import asyncio import functools -import sys import warnings from typing import ( Any, @@ -20,11 +19,12 @@ import jinja2 from aiohttp import web from aiohttp.abc import AbstractView +from typing_extensions import Protocol from .helpers import GLOBAL_HELPERS from .typedefs import Filters -__version__ = "1.3.0" +__version__ = "1.4.0" __all__ = ("setup", "get_env", "render_template", "render_string", "template") @@ -40,33 +40,25 @@ _T = TypeVar("_T") _AbstractView = TypeVar("_AbstractView", bound=AbstractView) -if sys.version_info >= (3, 8): - from typing import Protocol - - class _TemplateWrapper(Protocol): - @overload - def __call__( - self, func: _SimpleTemplateHandler - ) -> Callable[[web.Request], Awaitable[web.StreamResponse]]: - ... - - @overload - def __call__( - self, func: Callable[[_AbstractView], _TemplateReturnType] - ) -> Callable[[_AbstractView], Awaitable[web.StreamResponse]]: - ... - - @overload - def __call__( - self, func: Callable[[_T, web.Request], _TemplateReturnType] - ) -> Callable[[_T, web.Request], Awaitable[web.StreamResponse]]: - ... - - -else: - _TemplateHandler = Callable[..., _TemplateReturnType] - _WebHandler = Callable[..., Awaitable[web.StreamResponse]] - _TemplateWrapper = Callable[[_TemplateHandler], _WebHandler] + +class _TemplateWrapper(Protocol): + @overload + def __call__( + self, func: _SimpleTemplateHandler + ) -> Callable[[web.Request], Awaitable[web.StreamResponse]]: + ... + + @overload + def __call__( + self, func: Callable[[_AbstractView], _TemplateReturnType] + ) -> Callable[[_AbstractView], Awaitable[web.StreamResponse]]: + ... + + @overload + def __call__( + self, func: Callable[[_T, web.Request], _TemplateReturnType] + ) -> Callable[[_T, web.Request], Awaitable[web.StreamResponse]]: + ... def setup( diff --git a/setup.py b/setup.py index 9d39a2dc..f477edbf 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def read(f): return open(os.path.join(os.path.dirname(__file__), f)).read().strip() -install_requires = ["aiohttp>=3.6.3", "jinja2>=2.10.1"] +install_requires = ["aiohttp>=3.6.3", "jinja2>=2.10.1", "typing_extensions>=3.7.4"] setup(