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
def blabla_call(command: List[str], modules: Optional[List[str]] = None) -> Tuple[int, str]:
if modules is None:
modules = []
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output_buffer = io.StringIO()
for line in process.stdout:
decoded_line = line.decode("utf-8")
sys.stdout.write(decoded_line)
output_buffer.write(decoded_line)
if process.returncode:
raise RuntimeError("Shell command failure")
return process.returncode, output_buffer.getvalue()
def make_step(options: Iterable[str]) -> Tuple[int, str]:
return blabla_call(["make"])
On the very last line of the function make_step the following warning is reported only when running with --strict enabled: warning: Returning Any from function declared to return "Tuple[int, str]".
This sounds like a type propagation bug of sorts in mypy since there is no error reported in the type defintion of blabla_call, but only further on does mypy get confused.
I've managed to eliminate Tuple as an issue, I still get this issue with just str: warning: Returning Any from function declared to return "str"
I've managed to get the same issue when I have the following file:
import sys
from typing import Optional, List
def call(command: List[str], modules: Optional[List[str]] = None) -> str:
if modules is None:
modules = []
output_buffer = io.StringIO()
return output_buffer.getvalue()
But I understand this, because this doesn't import io. However, the file where I have blabla_call defined has an import io at the top and it can execute without any errors (unfortunately I can't share the full file).
x: int = 'hi' also executes without errors. I will be glad to fix the bug, if you show the bug, currently from what I see everything works as expected.
This works fine when I run in python because the sys.path contains the folder which is one level up of blamodule folder (the root of the project). However, mypy does not seem to take this into consideration and it can't find blamodule to import in backends/Bla.py and thus it expects a return of Any.
Activity
ilevkivskyi commentedon Oct 13, 2017
I cannot reproduce this on master.
matzipan commentedon Oct 13, 2017
I'm on 0.530 and I can't see what changed in the meanwhile that fixed it.
matzipan commentedon Oct 13, 2017
Ah you are right. My testcase doesn't produce the issue.
matzipan commentedon Oct 13, 2017
I've managed to eliminate
Tupleas an issue, I still get this issue with juststr:warning: Returning Any from function declared to return "str"I've managed to get the same issue when I have the following file:
But I understand this, because this doesn't import
io. However, the file where I haveblabla_calldefined has animport ioat the top and it can execute without any errors (unfortunately I can't share the full file).ilevkivskyi commentedon Oct 13, 2017
Yes, everything unknown is
Any.x: int = 'hi'also executes without errors. I will be glad to fix the bug, if you show the bug, currently from what I see everything works as expected.matzipan commentedon Oct 13, 2017
Ok. I think I've narrowed down and located the issue.
I have the following directory structure:
With the following contents:
blamodule/__init__.pyblamodule/backends/__init__.pyblamodule/backends/Bla.pyblamodule/call_command.pyThis works fine when I run in python because the
sys.pathcontains the folder which is one level up ofblamodulefolder (the root of the project). However, mypy does not seem to take this into consideration and it can't findblamoduleto import inbackends/Bla.pyand thus it expects a return of Any.ilevkivskyi commentedon Oct 13, 2017
This may be related to #3277 but it doesn't look like a duplicate, since there are no explicit import cycle.
[-]Mypy strict mode is confused about return type[/-][+]Unexpected Any for complex import structure[/+]JukkaL commentedon Mar 8, 2018
Looks like this was fixed by #4695.