-
-
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
Add a typevar with a default to io.TextIOWrapper
#12286
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment has been minimized.
This comment has been minimized.
AlexWaygood
reviewed
Jul 6, 2024
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:180: error: Returning Any from function declared to return "str" [no-any-return]
+ src/_pytest/capture.py:180: error: "_WrappedBuffer" has no attribute "mode" [attr-defined]
- src/_pytest/capture.py:205: error: Item "None" of "TextIOWrapper | None" has no attribute "encoding" [union-attr]
+ src/_pytest/capture.py:205: error: Item "None" of "TextIOWrapper[_WrappedBuffer] | None" has no attribute "encoding" [union-attr]
+ src/_pytest/capture.py:552: error: Incompatible return value type (got "Buffer", expected "bytes") [return-value]
- src/_pytest/faulthandler.py:67: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno" [union-attr]
+ src/_pytest/faulthandler.py:67: error: Item "None" of "TextIOWrapper[_WrappedBuffer] | None" has no attribute "fileno" [union-attr]
urllib3 (https://github.com/urllib3/urllib3)
+ test/test_response.py:808: error: Unused "type: ignore" comment [unused-ignore]
+ test/test_response.py:808: error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "HTTPResponse" [type-var]
+ test/test_response.py:808: note: Error code "type-var" not covered by "type: ignore" comment
+ test/test_response.py:822: error: Unused "type: ignore" comment [unused-ignore]
+ test/test_response.py:822: error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "HTTPResponse" [type-var]
+ test/test_response.py:822: note: Error code "type-var" not covered by "type: ignore" comment
+ test/test_response.py:829: error: Unused "type: ignore" comment [unused-ignore]
+ test/test_response.py:829: error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "HTTPResponse" [type-var]
+ test/test_response.py:829: note: Error code "type-var" not covered by "type: ignore" comment
pandas (https://github.com/pandas-dev/pandas)
+ pandas/io/common.py:915: error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "_IOWrapper | BaseBuffer" [type-var]
+ pandas/io/common.py:916: error: Unused "type: ignore" comment [unused-ignore]
werkzeug (https://github.com/pallets/werkzeug)
- tests/test_wsgi.py:158: error: Incompatible types in assignment (expression has type "TextIOWrapper", variable has type "LimitedStream") [assignment]
+ tests/test_wsgi.py:158: error: Incompatible types in assignment (expression has type "TextIOWrapper[BufferedReader]", variable has type "LimitedStream") [assignment]
black (https://github.com/psf/black)
- src/black/files.py:433:16: error: Incompatible return value type (got "Union[TextIOWrapper, StreamWrapper]", expected "Union[TextIOWrapper, AnsiToWin32]") [return-value]
+ src/black/files.py:433:16: error: Incompatible return value type (got "Union[TextIOWrapper[_WrappedBuffer], StreamWrapper]", expected "Union[TextIOWrapper[_WrappedBuffer], AnsiToWin32]") [return-value]
- src/black/__init__.py:978:17: error: Incompatible types in assignment (expression has type "Union[TextIOWrapper, AnsiToWin32]", variable has type "TextIOWrapper") [assignment]
+ src/black/__init__.py:978:17: error: Incompatible types in assignment (expression has type "Union[TextIOWrapper[_WrappedBuffer], AnsiToWin32]", variable has type "TextIOWrapper[_WrappedBuffer]") [assignment]
- src/black/__init__.py:1032:21: error: Incompatible types in assignment (expression has type "Union[TextIOWrapper, AnsiToWin32]", variable has type "TextIOWrapper") [assignment]
+ src/black/__init__.py:1032:21: error: Incompatible types in assignment (expression has type "Union[TextIOWrapper[_WrappedBuffer], AnsiToWin32]", variable has type "TextIOWrapper[Union[BinaryIO, Any]]") [assignment]
rich (https://github.com/Textualize/rich)
- rich/console.py:92: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno" [union-attr]
+ rich/console.py:92: error: Item "None" of "TextIOWrapper[_WrappedBuffer] | None" has no attribute "fileno" [union-attr]
- rich/console.py:96: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno" [union-attr]
+ rich/console.py:96: error: Item "None" of "TextIOWrapper[_WrappedBuffer] | None" has no attribute "fileno" [union-attr]
- rich/console.py:100: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno" [union-attr]
+ rich/console.py:100: error: Item "None" of "TextIOWrapper[_WrappedBuffer] | None" has no attribute "fileno" [union-attr]
ibis (https://github.com/ibis-project/ibis)
- ibis/backends/sqlite/tests/conftest.py:44: error: Incompatible types in assignment (expression has type "TextIOWrapper", variable has type "StringIO") [assignment]
+ ibis/backends/sqlite/tests/conftest.py:44: error: Incompatible types in assignment (expression has type "TextIOWrapper[_WrappedBuffer]", variable has type "StringIO") [assignment]
streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/web/server/component_request_handler_test.py: note: In function "test_support_binary_files_request":
- lib/tests/streamlit/web/server/component_request_handler_test.py:195:38: error: Argument 1 to "TextIOWrapper" has incompatible type "str"; expected "_WrappedBuffer" [arg-type]
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/filesystems.py:359: error: Incompatible types in assignment (expression has type "Path", variable has type "TextIOWrapper") [assignment]
+ src/prefect/filesystems.py:359: error: Incompatible types in assignment (expression has type "Path", variable has type "TextIOWrapper[_WrappedBuffer]") [assignment]
- src/prefect/filesystems.py:360: error: "TextIOWrapper" has no attribute "relative_to" [attr-defined]
+ src/prefect/filesystems.py:360: error: "TextIOWrapper[_WrappedBuffer]" has no attribute "relative_to" [attr-defined]
- src/prefect/filesystems.py:369: error: "TextIOWrapper" has no attribute "is_dir" [attr-defined]
+ src/prefect/filesystems.py:369: error: "TextIOWrapper[_WrappedBuffer]" has no attribute "is_dir" [attr-defined]
- src/prefect/filesystems.py:372: error: "TextIOWrapper" has no attribute "as_posix" [attr-defined]
+ src/prefect/filesystems.py:372: error: "TextIOWrapper[_WrappedBuffer]" has no attribute "as_posix" [attr-defined]
|
srittau
approved these changes
Jul 10, 2024
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.
LGTM, the new primer hit look like risky code that should at least get a # type: ignore
.
Yeah, I agree - this is a risky one. Revert is always an option. IO is hard :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Let's try this :)
Refs #11420
Refs #11418