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

    Labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy