Skip to content

Conversation

@srittau
Copy link
Collaborator

@srittau srittau commented Feb 24, 2025

Works towards #13495

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@srittau
Copy link
Collaborator Author

srittau commented Feb 24, 2025

Looking at the primer hits: Both LimitedStream (from werkzeug) and HTTPResponse (from urllib3) have wrong annotations for their readinto() methods: BufferedReader (both, the C and Python implementation) sends a memoryview to self.raw.readinto(), while the libraries's readinto() methods are annotated as accepting only bytearray. But their implementation actually accept memoryviews:

@srittau srittau marked this pull request as ready for review February 24, 2025 19:26
@srittau
Copy link
Collaborator Author

srittau commented May 11, 2025

Pingity pong. If this gets merged, I'd try the same with BufferedWriter to work towards fixing #13495.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/elements/audio_test.py:78:38: error: Argument 1 to "_calculate_file_id" has incompatible type "Union[str, Path, bytes, BytesIO, RawIOBase, BufferedReader, Any, None]"; expected "bytes"  [arg-type]
+ lib/tests/streamlit/elements/audio_test.py:78:38: error: Argument 1 to "_calculate_file_id" has incompatible type "Union[str, Path, bytes, BytesIO, RawIOBase, BufferedReader[_BufferedReaderStream], Any, None]"; expected "bytes"  [arg-type]

werkzeug (https://github.com/pallets/werkzeug)
- tests/test_wsgi.py:158: error: Incompatible types in assignment (expression has type "TextIOWrapper[BufferedReader]", variable has type "LimitedStream")  [assignment]
+ tests/test_wsgi.py:158: error: Incompatible types in assignment (expression has type "TextIOWrapper[BufferedReader[LimitedStream]]", variable has type "LimitedStream")  [assignment]
+ tests/test_wsgi.py:158: error: Value of type variable "_BufferedReaderStreamT" of "BufferedReader" cannot be "LimitedStream"  [type-var]

urllib3 (https://github.com/urllib3/urllib3)
+ test/test_response.py:770: error: Unused "type: ignore" comment  [unused-ignore]
+ test/test_response.py:770: error: Value of type variable "_BufferedReaderStreamT" of "BufferedReader" cannot be "HTTPResponse"  [type-var]
+ test/test_response.py:770: note: Error code "type-var" not covered by "type: ignore" comment
+ test/test_response.py:782: error: Unused "type: ignore" comment  [unused-ignore]
+ test/test_response.py:782: error: Value of type variable "_BufferedReaderStreamT" of "BufferedReader" cannot be "HTTPResponse"  [type-var]
+ test/test_response.py:782: note: Error code "type-var" not covered by "type: ignore" comment
+ test/test_response.py:787: error: Unused "type: ignore" comment  [unused-ignore]
+ test/test_response.py:787: error: Value of type variable "_BufferedReaderStreamT" of "BufferedReader" cannot be "HTTPResponse"  [type-var]
+ test/test_response.py:787: note: Error code "type-var" not covered by "type: ignore" comment
+ test/test_response.py:800: error: Unused "type: ignore" comment  [unused-ignore]
+ test/test_response.py:800: error: Value of type variable "_BufferedReaderStreamT" of "BufferedReader" cannot be "HTTPResponse"  [type-var]
+ test/test_response.py:800: note: Error code "type-var" not covered by "type: ignore" comment

materialize (https://github.com/MaterializeInc/materialize)
- misc/python/materialize/mzbuild.py:825: error: Incompatible types in assignment (expression has type "BufferedRandom", variable has type "BufferedReader")  [assignment]
+ misc/python/materialize/mzbuild.py:825: error: Incompatible types in assignment (expression has type "BufferedRandom", variable has type "BufferedReader[_BufferedReaderStream]")  [assignment]

@srittau srittau merged commit 1ebbbee into python:main May 11, 2025
64 checks passed
@srittau srittau deleted the buffered-reader branch May 11, 2025 14:24
mmingyu pushed a commit to mmingyu/typeshed that referenced this pull request May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants