Closed as not planned
Description
Feature
Example:
cdef foo(): # Type: Any
...
return ...
def bar() -> Any:
if bool:
return foo()
else:
var = foo() + 1
# forgot to return so implicitly return None which is a valid Any type
mypy won't flag this as an error
Proposed functionality example:
cdef foo(): # Type: Any
...
return ...
def bar() -> NoImplicit[Any]: # the new function specific NoImplicit type specifier
if bool:
return foo()
else:
var = foo() + foo()
# forgot to return
mypy flags it. error: Implicit return [None]
sometimes when using cython functions it is difficult to specify the return type and sometimes the exact type is not important. I just want to specify that the return is not implicit for only some functions in a large codebase.
Its possible to cast the return type and specify but it seems overly complex and messy when does this way:
cdef foo():
...
return ...
def bar() -> List[Union[int, bytes, float]], List[Union[str, int, bytes]
if bool:
return cast(List[Union[int, bytes, float]], List[Union[str, int, bytes], foo())
else:
var = foo() + foo()
# forgot to return. error: Missing return statement [return]
And then imagine how cluttered it gets after calling foo hundreds of times across the codebase