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
from typing import Optional
def is_not_none(x)-> bool:
"""
mypy:inline
"""
return x is not None # mypy:inline
# sample.py:16: error: Unsupported left operand type for + ("None")
# sample.py:16: note: Left operand is of type "Optional[str]"
def being_tested(x: Optional[str]) -> str:
if is_not_none(x):
return x + "a"
return ""
The variable "x" can't be None, because the check is performed outside.
I don't know how difficult it would be to retrieve the instruction "inline" inside the docstring, and perform on-the fly inlining of the function body, whenever it is encountered. I
The "inline" instruction can be in comments.
So here the modified version would look like:
def being_tested(x: Optional[str]) -> str:
if (x is not None):
return x + "a"
return ""
Only one-liners would be candidates for inlining, the first and the only expression after the return statement.
This would solve the false error above.
I am not sure however how line numbers would be handled, when reporting in the console.
Does this suggestion even makes sens?
The text was updated successfully, but these errors were encountered:
I think a decorator like @inline would be a better syntax. Anyway, I think this may be tricky and I rather prefer better support for literal types + NoReturn, see e.g. #5206 and #4063
Current behavior is following:
The variable "x" can't be None, because the check is performed outside.
I don't know how difficult it would be to retrieve the instruction "inline" inside the docstring, and perform on-the fly inlining of the function body, whenever it is encountered. I
The "inline" instruction can be in comments.
So here the modified version would look like:
Only one-liners would be candidates for inlining, the first and the only expression after the return statement.
This would solve the false error above.
I am not sure however how line numbers would be handled, when reporting in the console.
Does this suggestion even makes sens?
The text was updated successfully, but these errors were encountered: