Skip to content
New issue

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

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

Already on GitHub? # to your account

Incorrect type if annotation comes before assignment #11837

Closed
Dreamsorcerer opened this issue Dec 23, 2021 · 1 comment
Closed

Incorrect type if annotation comes before assignment #11837

Dreamsorcerer opened this issue Dec 23, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@Dreamsorcerer
Copy link
Contributor

Dreamsorcerer commented Dec 23, 2021

        method: Optional[Callable[[], Awaitable[StreamResponse]]]
        method = getattr(self, self.request.method.lower(), None)
        reveal_type(method)
aiohttp/web_urldispatcher.py:934: note: Revealed type is "Union[Any, None]"

vs.

        method: Optional[Callable[[], Awaitable[StreamResponse]]] = getattr(
            self, self.request.method.lower(), None)
        reveal_type(method)
aiohttp/web_urldispatcher.py:934: note: Revealed type is "Union[def () -> typing.Awaitable[aiohttp.web_response.StreamResponse], None]"

Expectation is that both versions should have the same type (and not be Any).

Tested with mypy 0.930.

Full code at: https://github.com/aio-libs/aiohttp/pull/6452/files#diff-9632858c8fdd45d817126b2735f763b9a2e24fb2800122eb2cb0c9a3b89c85c1

@Dreamsorcerer Dreamsorcerer added the bug mypy got something wrong label Dec 23, 2021
@erictraut
Copy link

Mypy doesn't currently apply narrowing to assignments if the assignment occurs on the same line as the type annotation.

This is a duplicate of #2008.

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants