-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Cannot infer type argument 1 of "shutil.copyfileobj" with mypy 0.780 #4201
Comments
The relevant shutil types haven't changed since 2018. If this is a typeshed issue, it might be related to changes in IO types (although I'm not quite sure what has made it to which mypy version). I think this is a mypy issue, because throwing in Note that your code does crash when I run it, presumably because you need to open srcfp with "rb", although you do get the same error when you fix the mode. |
Okay, let me open it with mypy.
The code was just meant to be an example for type checking 😊 I didn't check it for correctness. |
Also how would I make sure that this is not the case between |
I believe the problem is with the order of the overloads of |
write() is inherited from IO[bytes], where it's defined as `def write(self, s: AnyStr) -> int: ...`. If AnyStr is bytes, this should accept bytes, bytearray, and memoryview, so the overload is unnecessary. Closes: python#4201
Thanks for the quick PR. Should I go ahead and close the related issue I opened with mypy about this? |
I think there is something weird going on with mypy, so let them analyze it. |
write() is inherited from IO[bytes], where it's defined as `def write(self, s: AnyStr) -> int: ...`. If AnyStr is bytes, this should accept bytes, bytearray, and memoryview, so the overload is unnecessary. Closes: #4201
write() is inherited from IO[bytes], where it's defined as `def write(self, s: AnyStr) -> int: ...`. If AnyStr is bytes, this should accept bytes, bytearray, and memoryview, so the overload is unnecessary. Closes: python#4201
Sorry to post to this old issue, but I still get this error: import shutil
from typing import IO
def _copy_data(src_file: IO[bytes]) -> None:
reveal_type(src_file)
shutil.copyfileobj(src_file, src_file)
What am I missing? For me the type hints should allow this:
|
@pmhahn, that's a mypy bug, not a typeshed bug (although it was exposed by a recent change in typeshed). It's already tracked in the mypy repo: please see python/mypy#15031 and python/mypy#14943. In general, please don't post on extremely old issues that haven't seen activity in three years :) In such cases, it's highly likely that the problem you're encountering will be a new bug, rather than the same issue that was reported and closed 3 years ago. That's indeed the case here. Please just open a new issue in the future! |
(python/mypy#14975 appears to fix the issue, but it's still under review by the mypy maintainers.) |
The following code used to pass mypy type check with
mypy 0.770
but doesn't work formypy 0.780
> mypy 0.770
> mypy 0.780
Do let me know if this not a typeshed issue, but instead is a mypy issue.
The text was updated successfully, but these errors were encountered: