You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot infer type argument 1 of "shutil.copyfileobj" with mypy 0.780 #4201
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 reveal_type(srcfp/destfp/shutil.copyfileobj) get me the same thing across both mypy versions.
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.
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 reveal_type(srcfp/destfp/shutil.copyfileobj) get me the same thing across both mypy versions.
Okay, let me open it with mypy.
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.
The code was just meant to be an example for type checking 😊 I didn't check it for correctness.
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).
Also how would I make sure that this is not the case between mypy 0.770 released on 10th March and mypy 0.780 released on 2nd June 2020.
I believe the problem is with the order of the overloads of BinaryIO.write(). The first overload is bytearray, the second is bytes. mypy tries to infer bytearray as the generic type, which causes problems. I don't see why the overloads are necessary anyway, so I will open a PR to remove them.
I believe the problem is with the order of the overloads of BinaryIO.write(). The first overload is bytearray, the second is bytes. mypy tries to infer bytearray as the generic type, which causes problems. I don't see why the overloads are necessary anyway, so I will open a PR to remove them.
Thanks for the quick PR. Should I go ahead and close the related issue I opened with mypy about this?
mypy-1.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl reports the following error:
# mypy mypy-bug.py
mypy-bug.py:6: note: Revealed type is "typing.IO[builtins.bytes]"
mypy-bug.py:7: error: Cannot infer type argument 1 of "copyfileobj" [misc]
Found 1 error in 1 file (checked 1 source 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!
Activity
hauntsaninja commentedon Jun 7, 2020
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
reveal_type(srcfp/destfp/shutil.copyfileobj)get me the same thing across both mypy versions.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.
deveshks commentedon Jun 7, 2020
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.
deveshks commentedon Jun 8, 2020
Also how would I make sure that this is not the case between
mypy 0.770released on 10th March andmypy 0.780released on 2nd June 2020.srittau commentedon Jun 8, 2020
I believe the problem is with the order of the overloads of
BinaryIO.write(). The first overload isbytearray, the second isbytes. mypy tries to inferbytearrayas the generic type, which causes problems. I don't see why the overloads are necessary anyway, so I will open a PR to remove them.Remove BinaryIO.write()
deveshks commentedon Jun 8, 2020
Thanks for the quick PR. Should I go ahead and close the related issue I opened with mypy about this?
srittau commentedon Jun 8, 2020
I think there is something weird going on with mypy, so let them analyze it.
Remove BinaryIO.write() (#4203)
Remove BinaryIO.write() (python#4203)
pmhahn commentedon May 11, 2023
Sorry to post to this old issue, but I still get this error:
mypy-1.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whlreports the following error:What am I missing? For me the type hints should allow this:
AlexWaygood commentedon May 11, 2023
@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!
AlexWaygood commentedon May 11, 2023
(python/mypy#14975 appears to fix the issue, but it's still under review by the mypy maintainers.)