Skip to content
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

Stubs for filecmp are missing Pathlike for common argument #7034

Closed
bersbersbers opened this issue Jan 25, 2022 · 8 comments · Fixed by #7147
Closed

Stubs for filecmp are missing Pathlike for common argument #7034

bersbersbers opened this issue Jan 25, 2022 · 8 comments · Fixed by #7147
Labels
stubs: false positive Type checkers report false errors

Comments

@bersbersbers
Copy link
Contributor

bug.py:

"""Demo mypy bug."""
import filecmp
from pathlib import Path

d = Path.home()
filecmp.cmpfiles(d, d, d.glob("*"))

mypy bug.py:

bug.py:6: error: Value of type variable "AnyStr" of "cmpfiles" cannot be "Path"
Found 1 error in 1 file (checked 1 source file)

I guess common should be Iterable[AnyStr | PathLike[AnyStr]]:

def cmpfiles(
a: AnyStr | PathLike[AnyStr], b: AnyStr | PathLike[AnyStr], common: Iterable[AnyStr], shallow: int | bool = ...
) -> tuple[list[AnyStr], list[AnyStr], list[AnyStr]]: ...

Related: #3858, #3864

@srittau srittau added the stubs: false positive Type checkers report false errors label Jan 25, 2022
@srittau
Copy link
Collaborator

srittau commented Jan 25, 2022

Sounds right. All arguments are just passed to to os.path.join(), which accepts PathLikes. PR welcome!

@itaisteinherz
Copy link
Contributor

I'd like to work on this.

@bersbersbers
Copy link
Contributor Author

Will I have to wait for a new release of mypy for this to be effective or is there another way to update the typeshed? E.g., uninstalling and installing mypy did not help.

@AlexWaygood
Copy link
Member

Will I have to wait for a new release of mypy for this to be effective or is there another way to update the typeshed? E.g., uninstalling and installing mypy did not help.

If you clone typeshed, you can use mypy with the --custom-typeshed-dir option. But yeah, you'll have to wait until mypy 0.940 (at least) for mypy's vendored copy of these stubs to be updated.

@bersbersbers
Copy link
Contributor Author

Works great, thanks everybody!

@AlexWaygood
Copy link
Member

Works great, thanks everybody!

Awesome!

@bersbersbers
Copy link
Contributor Author

Btw, after cloning, MYPYPATH=/data/bers/typeshed/stdlib mypy bug.py also works for this example.

@bersbersbers
Copy link
Contributor Author

For the record, mypy 0.942 has not yet picked this up (in line with the history of the typeshed subdirectory at https://github.com/python/mypy/commits/v0.942/mypy/typeshed). python/mypy#12321 should have it at one point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants