Skip to content

Commit

Permalink
Merge branch 'master' into async
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Nov 8, 2020
2 parents a4e6b07 + 858bd57 commit a4dedbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fmt:

.PHONY: lint
lint: fmt
mypy --strict aiohttp_jinja2
mypy --strict

.PHONY: test
test:
Expand Down
43 changes: 12 additions & 31 deletions aiohttp_jinja2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,6 @@ def __call__(
...


else:
_TemplateHandler = Callable[..., _TemplateReturnType]
_WebHandler = Callable[..., Awaitable[web.StreamResponse]]
_TemplateWrapper = Callable[[_TemplateHandler], _WebHandler]

_ContextProcessor = Callable[[web.Request], Awaitable[Dict[str, Any]]]

_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]]
Expand Down Expand Up @@ -229,18 +202,26 @@ def template(
status: int = 200,
) -> _TemplateWrapper:
@overload
def wrapper(func: _SimpleTemplateHandler) -> Callable[[web.Request], Awaitable[web.StreamResponse]]:
def wrapper(
func: _SimpleTemplateHandler,
) -> Callable[[web.Request], Awaitable[web.StreamResponse]]:
...

@overload
def wrapper(func: Callable[[_AbstractView], _TemplateReturnType]) -> Callable[[_AbstractView], Awaitable[web.StreamResponse]]:
def wrapper(
func: Callable[[_AbstractView], _TemplateReturnType]
) -> Callable[[_AbstractView], Awaitable[web.StreamResponse]]:
...

@overload
def wrapper(func: Callable[[_T, web.Request], _TemplateReturnType]) -> Callable[[_T, web.Request], Awaitable[web.StreamResponse]]:
def wrapper(
func: Callable[[_T, web.Request], _TemplateReturnType]
) -> Callable[[_T, web.Request], Awaitable[web.StreamResponse]]:
...

def wrapper(func: Callable[..., _TemplateReturnType]) -> Callable[..., Awaitable[web.StreamResponse]]:
def wrapper(
func: Callable[..., _TemplateReturnType]
) -> Callable[..., Awaitable[web.StreamResponse]]:
@functools.wraps(func)
async def wrapped(*args: Any) -> web.StreamResponse:
if asyncio.iscoroutinefunction(func):
Expand Down

0 comments on commit a4dedbb

Please sign in to comment.