Closed
Description
I have this code which was accepted in a older version (0.6xx?) of mypy:
import pathlib
import shutil
from typing import Union
def f(x: Union[str, pathlib.Path]):
shutil.copyfile("bla", x)
But is not accepted by mypy 0.710:
error: Value of type variable "_AnyPath" of "copyfile" cannot be "Union[str, Path]"
How should I fix my type annotations?
I tried this:
import os
import shutil
from typing import TypeVar
_AnyPath = TypeVar("_AnyPath", str, os.PathLike)
def f(x: _AnyPath):
shutil.copyfile("bla", x)
And that seems to work.
I asked this on StackOverflow but it was suggested to open a "bug/missing feature issue" here.
Metadata
Metadata
Assignees
Labels
No labels