-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixestopic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
In 0729b31 (#91982), @methane implemented encoding="locale"
support for TextIOWrapper.reconfigure
.
However, the implementation in _pyio.py
can't possibly work, as locale
is not imported in the scope it's used:
Line 2165 in 760ec89
encoding = locale.getencoding() |
it's only imported locally in __init__
:
Lines 2024 to 2031 in 760ec89
if encoding == "locale": | |
try: | |
import locale | |
except ImportError: | |
# Importing locale may fail if Python is being built | |
encoding = "utf-8" | |
else: | |
encoding = locale.getencoding() |
Thus causing python -c 'import _pyio as io; wrapper = io.TextIOWrapper(io.BytesIO(b"test")); wrapper.reconfigure(encoding="locale")'
to fail with:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.11/_pyio.py", line 2165, in reconfigure
encoding = locale.getencoding()
^^^^^^
NameError: name 'locale' is not defined. Did you mean: 'locals'?
(Found by running flake8
over Lib/
out of curiosity, see #93010 (comment))
Your environment
- CPython versions tested on: Python 3.11.0b1
- Operating system and architecture: Archlinux x86_64
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixestopic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error