You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, mypy will generate errors when a function is missing return statements in some execution paths. The only exceptions are when:
The function has a None or Any return type
The function has an empty body or a body that is just ellipsis (...). Empty functions are often used for abstract methods.
I propose that the second bullet point should only apply to abstract methods. Functions and non-abstract methods with an empty body or a body that is just ellipsis should produce a "Missing return statement" error as usual.
This behavior could be controlled with a feature flag such as --warn-no-return-empty.
Pitch
Apart from abstract methods, I don't see why empty functions/methods should be excluded from no-return checking. For example, the following function clearly does not satisfy its return type annotation:
def return_a_string() -> str:
pass
The same reasoning applies to methods. An empty method may indicate a programming error such as a missing @abstractmethod annotation.
from abc import ABC, abstractmethod
class MyABC(ABC):
@abstractmethod
def return_an_int(self) -> int: ...
# whoops, forgot to annotate with @abstractmethod
def return_a_string(self) -> str: ...
The text was updated successfully, but these errors were encountered:
Feature
According to the documentation for the
--no-warn-no-return
option:I propose that the second bullet point should only apply to abstract methods. Functions and non-abstract methods with an empty body or a body that is just ellipsis should produce a "Missing return statement" error as usual.
This behavior could be controlled with a feature flag such as
--warn-no-return-empty
.Pitch
Apart from abstract methods, I don't see why empty functions/methods should be excluded from no-return checking. For example, the following function clearly does not satisfy its return type annotation:
The same reasoning applies to methods. An empty method may indicate a programming error such as a missing
@abstractmethod
annotation.The text was updated successfully, but these errors were encountered: