Skip to content

Unreachable error with TypeVar #13843

@Dreamsorcerer

Description

@Dreamsorcerer

With:

from functools import wraps
from typing import Any, AsyncIterator, Awaitable, Callable, Coroutine, Optional, TypeVar, Union, overload

from aiohttp import web

_T = TypeVar("_T")
_RequestView = TypeVar("_RequestView", web.Request, web.View)

def atomic(coro: Callable[[_RequestView], Awaitable[_T]]):
    @wraps(coro)
    async def wrapper(request_or_view: _RequestView) -> _T:
        reveal_type(request_or_view)
        if isinstance(request_or_view, web.View):
            request = request_or_view.request
        else:
            request = request_or_view

I get an unreachable error on the last line. I suspect it is type checking twice with the TypeVar set to web.Request and then to web.View, which is resulting in an unreachable error. Rather odd that it doesn't produce a second unreachable error though...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions