summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2022-04-19 02:44:36 (GMT)
committerGitHub <noreply@github.com>2022-04-19 02:44:36 (GMT)
commit6fdb62b1fa344b9cdf1f221eac83404fb1980822 (patch)
tree97badf048e8285069490b1753bc1a77f997070e7 /Lib
parent39a54ba63850e081a4a5551a773df5b4d5b1d3cd (diff)
downloadcpython-6fdb62b1fa344b9cdf1f221eac83404fb1980822.zip
cpython-6fdb62b1fa344b9cdf1f221eac83404fb1980822.tar.gz
cpython-6fdb62b1fa344b9cdf1f221eac83404fb1980822.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/_pyio.py8
-rw-r--r--Lib/test/test_io.py12
2 files changed, 0 insertions, 20 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 0f33ed5..380a7a7 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -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
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index c86251d..45bf81b 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2736,18 +2736,6 @@ class TextIOWrapperTest(unittest.TestCase):
os.environ.clear()
os.environ.update(old_environ)
- @support.cpython_only
- @unittest.skipIf(sys.platform != "win32", "Windows-only test")
- @unittest.skipIf(sys.flags.utf8_mode, "utf-8 mode is enabled")
- def test_device_encoding(self):
- # Issue 15989
- import _testcapi
- b = self.BytesIO()
- b.fileno = lambda: _testcapi.INT_MAX + 1
- self.assertRaises(OverflowError, self.TextIOWrapper, b, encoding="locale")
- b.fileno = lambda: _testcapi.UINT_MAX + 1
- self.assertRaises(OverflowError, self.TextIOWrapper, b, encoding="locale")
-
def test_encoding(self):
# Check the encoding attribute is always set, and valid
b = self.BytesIO()