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
mypy raises error if list of command line arguments (passing to subprocess.call) contains items of different types (for example, str and pathlib.Path). It can be fixed by adding type hint to variable, but it's too annoying.
In the absence of an explicit annotation, mypy infers the type of cmd as being of type list[object] due to its preference for join/meet operations instead of unions in many situations (see #12056 for more examples of where this causes issues).
As a workaround, you can fix the error here by providing an explicit annotation:
importpathlibimportsubprocessfromosimportPathLike# either like this:cmd2: list[pathlib.Path|str] = [pathlib.Path('bash'), '-c', 'echo Hello']
subprocess.call(cmd2)
# or like this:cmd3: list[PathLike[str] |str] = [pathlib.Path('bash'), '-c', 'echo Hello']
subprocess.call(cmd3)
Or you can just pass the list to subprocess.call directly, without creating the cmd variable at all:
Bug Report
mypy raises error if list of command line arguments (passing to
subprocess.call
) contains items of different types (for example,str
andpathlib.Path
). It can be fixed by adding type hint to variable, but it's too annoying.To Reproduce
Expected Behavior
mypy should not raise any error.
Actual Behavior
Why can't mypy recognize
cmd
type asList[Union[pathlib.Path, str]]
, notList[object]
?Environment
The text was updated successfully, but these errors were encountered: