Skip to content

Deprecate codecs.open() #133036

Closed
Closed

Description

@methane

Discussion: https://discuss.python.org/t/deprecating-codecs-open/88135/

codecs.open() is used a lot because it was recommended in Python 2.
But open() (or io.open()) is recommended since Python 3.

It is a time to deprecate codecs.open().
Since it is still widely used, we won't schedule its removal.

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Apr 27, 2025
  2. self-assigned this
    on Apr 27, 2025
  3. added a commit that references this issue on Apr 27, 2025
  4. added a commit that references this issue on Apr 30, 2025
  5. ngoldbaum commented on Aug 7, 2025

    @ngoldbaum
    Contributor

    I don't know if this deserves a better clarification in the deprecation notice, but I hit a corner case that took me a few minutes to understand today. Perhaps commenting here will help someone else.

    I tried replacing codecs.open with open in a spot in pandas and hit this error:

    >               with open(as_json, "wb", encoding="utf8") as f:
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    E               ValueError: binary mode doesn't take an encoding argument
    

    I fixed it by replacing "wb" with "w". It seems codecs.open is a little more permissive here than open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions