Open
Description
When implementing #142 I encountered a tricky type annotation scenario and used a workaround.
The AnyPath
constructor instead of to_anypath
in the code referenced below runs fine, but mypy
complains. We should determine the right type annotations to use AnyPath(p)
instead of to_anypath
.
I couldn't use the AnyPath
constructor
For some reason, this was the only way I could make mypy
happy after the call here. Maybe you've got a nice solution:
cloudpathlib/cloudpathlib/cloudpath.py
Lines 695 to 697 in 8dca2ed
If I change that line to anypath.AnyPath(destination)
, I see these errors even if I # type: ignore
that line.
mypy cloudpathlib
cloudpathlib/cloudpath.py:699: error: Item "str" of "Union[str, _PathLike[Any], CloudPath]" has no attribute "exists"
cloudpathlib/cloudpath.py:699: error: Item "_PathLike[Any]" of "Union[str, _PathLike[Any], CloudPath]" has no attribute "exists"
cloudpathlib/cloudpath.py:699: error: Item "str" of "Union[str, _PathLike[Any], CloudPath]" has no attribute "is_file"
cloudpathlib/cloudpath.py:699: error: Item "_PathLike[Any]" of "Union[str, _PathLike[Any], CloudPath]" has no attribute "is_file"
cloudpathlib/cloudpath.py:704: error: Item "str" of "Union[str, _PathLike[Any], CloudPath]" has no attribute "mkdir"
cloudpathlib/cloudpath.py:704: error: Item "_PathLike[Any]" of "Union[str, _PathLike[Any], CloudPath]" has no attribute "mkdir"
cloudpathlib/cloudpath.py:716: error: Incompatible return value type (got "Union[str, _PathLike[Any], CloudPath]", expected "Union[Path, CloudPath]")
Found 7 errors in 1 file (checked 24 source files)
Originally posted by @pjbull in #142 (comment)