filecmp and tempfile can handle pathlib.Path#2267
filecmp and tempfile can handle pathlib.Path#2267scivision wants to merge 6 commits intopython:masterfrom
Conversation
|
Hmm, I think this may need to be split into Do the maintainers concur? The other option per https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#stub-versioning would be to use |
|
I would use |
filecmp and tempfile can handle pathlib.Path
filecmp and tempfile can handle pathlib.Path|
OK I believe the fixes are ready to go. |
| if sys.version_info >= (3, 6): | ||
| def cmp(f1: Union[bytes, Text, os.PathLike], f2: Union[bytes, Text, os.PathLike], | ||
| shallow: Union[int, bool] = ...) -> bool: ... | ||
| def cmpfiles(a: Union[AnyStr, os.PathLike], b: Union[AnyStr, os.PathLike], common: Iterable[Union[AnyStr, os.PathLike]], |
There was a problem hiding this comment.
Because this uses AnyStr, we should ideally also use a type variable in the PathLike case (so PathLike[AnyStr]). But this sort of things tends to run into mypy bugs sometimes. We should check a few cases like these:
cmpfiles(bytes, bytes)returnsTuple[List[bytes], ...]cmpfiles(str, str)returnsTuple[List[str], ...]cmpfiles(PathLike[str], PathLike[str])returnsTuple[List[str], ...]cmpfiles(PathLike[str], bytes)is an error
You can check these in mypy by using reveal_type.
| hide: Optional[Sequence[AnyStr]] = ...) -> None: ... | ||
|
|
||
| if sys.version_info >= (3, 6): | ||
| def __init__(self, a: Union[AnyStr, os.PathLike], b: Union[AnyStr, os.PathLike], |
There was a problem hiding this comment.
Same here, we should use PathLike[AnyStr] but should verify it actually works.
Also, do the ignore and hide parameters also accept paths?
| def gettempprefixb() -> bytes: ... | ||
|
|
||
| if sys.version_info >= (3, 6): | ||
| def TemporaryFile( |
There was a problem hiding this comment.
Most of these functions have the same issue with AnyStr.
|
@scivision Are you still interested in this pull request? |
|
Hi @srittau it seems like the fix grew bigger. I don't have much time lately so I have just been using |
|
Thank you for your work on this. I am closing this PR for now. Please reopen it or open a new PR if you wish to finish it. |
filecmpcan handlepathlib.Path, including:Before this patch, doing something like
would work fine when executed, but would give
mypyerrors likeAfter this change, type checking works as expected