mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Do not emit return errors if node is deferred

Open kreathon opened this issue 3 years ago • 2 comments

Motivation

If a variable is unknown / the function node deferred, mypy should not emit Implicit return in function which does not return or Missing return statement errors.

Assume current_app.aborter is a NoReturn method and the function node gets deferred because of current_app. There should not be an Implicit return in function which does not return error (assuming the option warn_no_return is enabled).

def abort(code: int, *args: Any, **kwargs: Any) -> "NoReturn":

    current_app.aborter(code, *args, **kwargs)

An example (, that was given by @davidism) can be found in the Flask abort function.

See https://github.com/python/mypy/issues/12779 for more details.

Implementation

Ensure to check self.current_node_deferred before emitting the errors.

Test Plan

I already tried to create a test case, but could not produce an example where var.is_ready is False (-> function gets deferred). Does anyone has an idea how to create a such a case on purpose?

Closes https://github.com/python/mypy/issues/12779

kreathon avatar Jul 23 '22 14:07 kreathon

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Jul 23 '22 15:07 github-actions[bot]

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Jul 31 '22 08:07 github-actions[bot]