Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreachable error with TypeVar #13843

Closed
Dreamsorcerer opened this issue Oct 8, 2022 · 1 comment
Closed

Unreachable error with TypeVar #13843

Dreamsorcerer opened this issue Oct 8, 2022 · 1 comment
Labels
bug mypy got something wrong

Comments

@Dreamsorcerer
Copy link
Contributor

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...

@Dreamsorcerer Dreamsorcerer added the bug mypy got something wrong label Oct 8, 2022
@brianschubert
Copy link
Collaborator

Fixed in #18217, which should land with mypy v1.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants