gh-91526: io: Remove device encoding support from TextIOWrapper (GH-91529)

`TextIOWrapper.__init__()` called `os.device_encoding(file.fileno())` if fileno is 0-2 and encoding=None.
But it is very rarely works, and never documented behavior.
This commit is contained in:
Inada Naoki 2022-04-19 11:44:36 +09:00 committed by GitHub
parent 39a54ba638
commit 6fdb62b1fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 70 deletions

View file

@ -2021,14 +2021,6 @@ class TextIOWrapper(TextIOBase):
self._check_newline(newline)
encoding = text_encoding(encoding)
if encoding == "locale" and sys.platform == "win32":
# On Unix, os.device_encoding() returns "utf-8" instead of locale encoding
# in the UTF-8 mode. So we use os.device_encoding() only on Windows.
try:
encoding = os.device_encoding(buffer.fileno()) or "locale"
except (AttributeError, UnsupportedOperation):
pass
if encoding == "locale":
try:
import locale