Skip to content

codecs.open doesn't support encoding='locale' in Python3.11 #120406

Open
@Amethiel

Description

@Amethiel

Bug report

Bug description:

from 3.10, io.text_encoding may return 'locale' if encoding is None, and the function open can support it well, like:

>>> open('/dev/null',encoding=io.text_encoding(None))
<_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>

but codes.open raised an error when i was doing this:

>>> codecs.open('/dev/null',encoding=io.text_encoding(None))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen codecs>", line 910, in open
LookupError: unknown encoding: locale

>>> codecs.open('/dev/null',encoding='locale')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen codecs>", line 910, in open
LookupError: unknown encoding: locale

and codes.open can deal None correctly:

>>> codecs.open('/dev/null',encoding=None)
<_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>

My Python version is:
Python 3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)] on win32

CPython versions tested on:

3.11

Operating systems tested on:

Linux, Windows

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions