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

Add a typevar with a default to io.TextIOWrapper #12286

Merged
merged 5 commits into from
Jul 10, 2024

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Jul 6, 2024

Let's try this :)

Refs #11420
Refs #11418

This comment has been minimized.

stdlib/io.pyi Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented 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]

Copy link
Collaborator

@srittau srittau left a 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.

@srittau srittau merged commit 9f2a9d8 into main Jul 10, 2024
63 checks passed
@srittau srittau deleted the io-textiowrapper-typevar-default branch July 10, 2024 09:41
@sobolevn
Copy link
Member Author

Yeah, I agree - this is a risky one. Revert is always an option. IO is hard :)

@srittau srittau added the topic: io I/O related issues label Jul 10, 2024
max-muoto pushed a commit to max-muoto/typeshed that referenced this pull request Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: io I/O related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants