# 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
The text was updated successfully, but these errors were encountered:
Bug report
In 0729b31 (#91982), @methane implemented
encoding="locale"
support forTextIOWrapper.reconfigure
.However, the implementation in
_pyio.py
can't possibly work, aslocale
is not imported in the scope it's used:cpython/Lib/_pyio.py
Line 2165 in 760ec89
it's only imported locally in
__init__
:cpython/Lib/_pyio.py
Lines 2024 to 2031 in 760ec89
Thus causing
python -c 'import _pyio as io; wrapper = io.TextIOWrapper(io.BytesIO(b"test")); wrapper.reconfigure(encoding="locale")'
to fail with:(Found by running
flake8
overLib/
out of curiosity, see #93010 (comment))Your environment
The text was updated successfully, but these errors were encountered: