-
-
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
[alt] typing: accept buffers in IO.write
#9861
Conversation
Co-authored-by: JelleZijlstra <jelle.zijlstra@gmail.com>
@overload | ||
def write(self, s: AnyStr) -> int: ... |
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.
Is the third overload needed? This should be covered by the preceding two overloads. (Same for further overloads below.)
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.
Unfortunately the test cases I've added don't pass for pyright unless we include this third overload. This is due to a design decision by pyright in the way it handles contrained TypeVar
s that leads to different behaviour from mypy: https://github.com/microsoft/pyright/blob/main/docs/mypy-comparison.md#constrained-type-variables
It's the same issue that led to microsoft/pyright#4534 being filed, which we then fixed over at typeshed in #9592.
Diff from mypy_primer, showing the effect of this PR on open source code: rich (https://github.com/Textualize/rich)
+ rich/progress.py:173: error: Definition of "writelines" in base class "IOBase" is incompatible with definition in base class "IO" [misc]
psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/copy.py:464: error: Unused "type: ignore" comment
urllib3 (https://github.com/urllib3/urllib3)
+ test/test_ssltransport.py:443: error: Unused "type: ignore" comment
+ test/test_ssltransport.py:443: error: No overload variant of "write" of "IO" matches argument type "bytes" [call-overload]
+ test/test_ssltransport.py:443: note: Error code "call-overload" not covered by "type: ignore" comment
+ test/test_ssltransport.py:443: note: Possible overload variants:
+ test/test_ssltransport.py:443: note: def write(self, str, /) -> int
+ test/test_ssltransport.py:480: error: No overload variant of "write" of "IO" matches argument type "str" [call-overload]
+ test/test_ssltransport.py:480: note: Error code "call-overload" not covered by "type: ignore" comment
+ test/test_ssltransport.py:480: note: Possible overload variants:
+ test/test_ssltransport.py:480: note: def write(self, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], /) -> int
+ test/test_ssltransport.py:480: note: def write(self, bytes, /) -> int
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/main.py:963: error: Unused "type: ignore[arg-type]" comment
|
Two errors go away ( |
An alternative PR to #9084 (closes #9084)
Fixes #9082
Co-authored-by: JelleZijlstra jelle.zijlstra@gmail.com