Skip to content

Commit

Permalink
Use typing_estensions.Protocol on all supported Python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Nov 12, 2020
1 parent 72095b9 commit 12af5fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
50 changes: 21 additions & 29 deletions aiohttp_jinja2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import functools
import sys
import warnings
from typing import (
Any,
Expand All @@ -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")

Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 12af5fc

Please sign in to comment.