-
-
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
ConfigParser has incompatible type IO[Any]; expected TextIO #283
Comments
Likely the stub for |
@BoboTiG Would you like to contribute a fix? |
Yes, of course. Thanks for giving me that chance :) |
FWIW I've seen similar issues several times now. It's unfortunate that IO[str] and TextIO are not the same thing. Maybe we should make them the same, or else we should hunt down all uses of TextIO and change them to IO[str], or maybe we should just change open() and sys.std{in,out,err} to return TextIO? |
This was discussed before. |
Which is better? Completly remove the TextIO type or to specify both are the same? |
OK, did not see you answer at time. Do you want I send a PR to replace all TextIO? |
Let's start with fixing |
Good, I am working on. |
Instead of using TextIO and BinaryIO use IO[str] and IO[bytes] respectively to match the type returned by the open builtin. This follows the recommendations in python#283. The error that prompts this is reproduced via: ``` from email import message_from_file with open('email') as file_: email = message_from_file(file_) ``` Argument 1 to "message_from_file" has incompatible type IO[Any]; expected "TextIO"
Instead of using TextIO and BinaryIO use IO[str] and IO[bytes] respectively to match the type returned by the open builtin. This follows the recommendations in python#283. The error that prompts this is reproduced via: ``` from email import message_from_file with open('email') as file_: email = message_from_file(file_) ``` Argument 1 to "message_from_file" has incompatible type IO[Any]; expected "TextIO"
* Change (Py3) email message payload type The docstring of the Message get_payload method indicates that the possible return types include None and bytes. Additionally the set_payload method accepts bytes. Therefore I've changed the PayloadType to include bytes and the get_payload return type to be an Optional PayloadType. * Change email (Py3) message_from_file IO types Instead of using TextIO and BinaryIO use IO[str] and IO[bytes] respectively to match the type returned by the open builtin. This follows the recommendations in #283. The error that prompts this is reproduced via: ``` from email import message_from_file with open('email') as file_: email = message_from_file(file_) ``` Argument 1 to "message_from_file" has incompatible type IO[Any]; expected "TextIO"
Every few years, I write a program that uses .print_dfxml(), and I get a runtime error about type confusion between the writer argument needing to be str but being bytes. These error messages are sufficiently infrequent and obtuse that it always feels like it takes too long to jog my memory on how the matter was resolved last time. Most recently, thsi came about because a program I was writing was using tempfile.NamedTemporaryFile, but I forgot the opening mode by default is "w+b". This is now encoded in a pair of tests. This patch adds a type annotation, following the prescription in this Issue's comment thread to resolve mypy being confused about typing.IO[str] versus typing.TextIO: python/typeshed#283 Hopefully, users of static type-checkers in the future will be able to prevent this same confusion. Signed-off-by: Alex Nelson <[email protected]>
Hello,
This is a reference from python/mypy#1688.
I am testing mypy and cannot solve this error. I am using Python 3.5.1 and mypy 0.4.2 (same error with mypy 0.4.1). The snippet:
And
stats.ini
:[stats] lines = 2
Using the command line:
Could you please tell me what is going wrong here? Thank you in advance :)
The text was updated successfully, but these errors were encountered: