-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
filecmp and tempfile can handle pathlib.Path #2267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
filecmp
can handlepathlib.Path
, including:Before this patch, doing something like
would work fine when executed, but would give
mypy
errors likeAfter this change, type checking works as expected