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

New semanal: Spurious "Missing return statement" in async function #7058

Closed
JelleZijlstra opened this issue Jun 25, 2019 · 0 comments · Fixed by #7062
Closed

New semanal: Spurious "Missing return statement" in async function #7058

JelleZijlstra opened this issue Jun 25, 2019 · 0 comments · Fixed by #7062
Assignees
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high semantic-analyzer Problems that happen during semantic analysis

Comments

@JelleZijlstra
Copy link
Member

$ cat santa/scheduler/loop.py 
from typing import Any


async def loop() -> None:
    def signal_handler(signum: Any, frame: Any) -> None:
        nonlocal running
        running = False

    running = True
$ mypy --new-semantic-analyzer santa/scheduler/loop.py 
santa/scheduler/loop.py:4: error: Missing return statement
santa/scheduler/loop.py:6: error: No binding for nonlocal 'running' found

The second error is #7057, but the first error goes away if I fix that error (by removing the nonlocal or moving the running = True above the nested function).

I ran into this issue in two places in my code. I minimized the other one to this:

$ cat santa/lib/git_repo.py 
from typing import Any


async def ensure_exists(self) -> None:
    async def create_worktree_at(x: Any) -> None:
        await x.check_call(worktree_dir)
$ mypy --new-semantic-analyzer santa/lib/git_repo.py 
santa/lib/git_repo.py:4: error: Missing return statement
santa/lib/git_repo.py:5: error: Missing return statement
santa/lib/git_repo.py:6: error: Name 'worktree_dir' is not defined

Here too there is an unrelated error that has to trigger for the "Missing return statement" to appear. The original code actually had no errors, though.

@JelleZijlstra JelleZijlstra added the semantic-analyzer Problems that happen during semantic analysis label Jun 25, 2019
@JukkaL JukkaL added bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high labels Jun 25, 2019
@JukkaL JukkaL self-assigned this Jun 25, 2019
JukkaL added a commit that referenced this issue Jun 25, 2019
Previously if the body was analyzed in multiple iterations, the
return type could get multiple levels of Coroutine[...] wrappers.
Fixed the problem by applying the type wrapper only during the
final iteration (nothing was deferred in the function body).

Fixes #7058.
JukkaL added a commit that referenced this issue Jun 25, 2019
Previously if the body was analyzed in multiple iterations, the
return type could get multiple levels of Coroutine[...] wrappers.
Fixed the problem by applying the type wrapper only during the
final iteration (nothing was deferred in the function body).

Fixes #7058.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high semantic-analyzer Problems that happen during semantic analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants