typing.TextIO: add write_through and reconfigure.#8171
typing.TextIO: add write_through and reconfigure.#8171ppentchev wants to merge 1 commit intopython:masterfrom
typing.TextIO: add write_through and reconfigure.#8171Conversation
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
|
Hm. Okay. So the test suite seems to be correct: Python 3.7's typing module does indeed not declare TextIO.reconfigure() and TextIO.write_through. However, they are present in the actual sys.stdin/stdout/stderr objects. So... what do we do here? And okay, fine, "do nothing and add type: ignore on the sys.stdin.reconfgure() line" is an acceptable answer. |
|
This was already "fixed" in #4035, but that fix doesn't work because A couple things we could do instead:
You can also use |
|
typeshed's |
|
To be clear, here's how to do this with if isinstance(sys.stdout, io.TextIOWrapper) and sys.version_info >= (3, 7):
sys.stdout.reconfigure(encoding="UTF-8") |
|
Thanks, that helps a lot! And yes, I get it, the I/O types are, hm, complicated. So yeah, thanks, and sorry for the noise! |
Hi,
Thanks a lot for taking care of typeshed, mypy, and the related projects!
What do you think about the attached trivial patch that makes it possible to use e.g.
sys.stdin.reconfigure(encoding="UTF-8")in cases when it is needed?Thanks again, and keep up the great work!
G'luck,
Peter