-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Tighten TextIOWrapper buffer types #10266
Conversation
This matches the documentation, which says: > A buffered text stream providing higher-level access to a BufferedIOBase > buffered binary stream. Cf python#10229
Also, the current annotations are unsound. You can pass in any |
Diff from mypy_primer, showing the effect of this PR on open source code: pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/capture.py:174: error: Returning Any from function declared to return "str" [no-any-return]
+ src/_pytest/capture.py:174: error: "BufferedIOBase" has no attribute "mode" [attr-defined]
+ src/_pytest/capture.py:466: error: Argument 1 to "EncodedFile" has incompatible type "IO[bytes]"; expected "BufferedIOBase" [arg-type]
+ testing/test_capture.py:1635: error: Argument 1 to "EncodedFile" has incompatible type "BinaryIO"; expected "BufferedIOBase" [arg-type]
rich (https://github.com/Textualize/rich)
+ rich/progress.py:1363: error: Argument 1 to "TextIOWrapper" has incompatible type "_Reader"; expected "BufferedIOBase" [arg-type]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/util/ssltransport.py:165: error: Argument 1 to "TextIOWrapper" has incompatible type "BinaryIO"; expected "BufferedIOBase" [arg-type]
streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/web/server/component_request_handler_test.py:161:38: error: Argument 1 to "TextIOWrapper" has incompatible type "str"; expected "IO[bytes]" [arg-type]
+ lib/tests/streamlit/web/server/component_request_handler_test.py:161:38: error: Argument 1 to "TextIOWrapper" has incompatible type "str"; expected "BufferedIOBase" [arg-type]
black (https://github.com/psf/black)
+ src/black/__init__.py:844:17: error: Argument 1 to "TextIOWrapper" has incompatible type "BinaryIO"; expected "BufferedIOBase" [arg-type]
+ src/black/__init__.py:888:13: error: Argument 1 to "TextIOWrapper" has incompatible type "BinaryIO"; expected "BufferedIOBase" [arg-type]
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/main.py:55: note: In module imported here:
+ cwltool/cwlprov/writablebagfile.py: note: In function "write_bag_file":
+ cwltool/cwlprov/writablebagfile.py:119:30: error: Argument 1 to "TextIOWrapper" has incompatible type "BinaryIO"; expected "BufferedIOBase" [arg-type]
+ cwltool/main.py: note: In function "main":
+ cwltool/main.py:965:43: error: Argument 1 to "TextIOWrapper" has incompatible type "BinaryIO"; expected "BufferedIOBase" [arg-type]
|
I'd be interested to see the mypy_primer results if we tried making it generic. It might be very disruptive, but it also might not. |
Ok, not sure why I replicated @JelleZijlstra's issue #10229. I tried to actually address one of the suggestions I made in there, but accidentally replicated it mostly. Although this PR is a little but more extensive, as it also adds |
I suggest we merge the two other PRs first, rerun the tests here and then I'll also do a test with a generic |
Incorporates changes from python#10266, so we don't have two PRs open.
I merged the additional changes into #10229, closing this here. |
This matches the documentation, which says:
Cf #10229