GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-133036: Deprecate codecs.open by methane · Pull Request #133038 · python/cpython

Conversation

@methane

@methane methane commented Apr 27, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Deprecate codecs.open() #133036

📚 Documentation preview 📚: https://cpython-previews--133038.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@methane
pythongh-133036: deprecate codecs.open
655759b
@methane methane added the stdlib Standard Library Python modules in the Lib/ directory label Apr 27, 2025
@methane
methane requested review from malemburg and vstinner April 27, 2025 06:24
@methane methane added this to Codecs and encodings issues Apr 27, 2025
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 27, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Apr 27, 2025
Deprecate codecs.open() #133036
Closed
vstinner
vstinner approved these changes Apr 27, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_codecs.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Apr 27, 2025
hugovk
hugovk reviewed Apr 27, 2025
View reviewed changes
Comment thread Lib/test/test_codecs.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

StanFromIreland
StanFromIreland reviewed Apr 27, 2025
View reviewed changes
Comment thread Doc/library/codecs.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

StanFromIreland
StanFromIreland reviewed Apr 27, 2025
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2025-04-27-15-21-05.gh-issue-133036.HCNYA7.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 27, 2025

Copy link
Copy Markdown
Member

Aha, 2 tests failed on the CI: test_multibytecodec and test_sax.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

malemburg
malemburg requested changes Apr 27, 2025
View reviewed changes

@malemburg malemburg left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. You are still missing a few places which need to be updated:

  • Lib/test/test_multibytecodec.py uses codecs.open()
  • Lib/test/test_sax.py uses codecs.open()
  • Lib/_pyio.py references codecs.open() for non-text encodings
  • Modules/_io/textio.c mentions codecs.open() as an alternative command

There may be more places. I have only searched for "codecs.open".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting merge labels Apr 27, 2025
@bedevere-app

bedevere-app Bot commented Apr 27, 2025

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

methane added 2 commits April 28, 2025 16:40
@methane
codecs_open_nowarn -> codecs_open_no_warn
47ebf4f
@methane
fix tests
ff0d25d
@vstinner

vstinner commented Apr 28, 2025

Copy link
Copy Markdown
Member

Tests fail on Windows:

ERROR: test_code_page_decode_flags (test.test_codecs.CodePageTest.test_code_page_decode_flags)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\cpython\cpython\Lib\test\test_codecs.py", line 3466, in test_code_page_decode_flags
    if is_code_page_present(cp):
       ~~~~~~~~~~~~~~~~~~~~^^^^
  File "D:\a\cpython\cpython\Lib\test\test_codecs.py", line 44, in is_code_page_present
    class CPINFOEXW(ctypes.Structure):
                    ^^^^^^
NameError: name 'ctypes' is not defined. Did you mean: 'type'? Or did you forget to import 'ctypes'?
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@methane
remove codecs.open from error message
cba4e03
@vstinner

vstinner commented Apr 28, 2025

Copy link
Copy Markdown
Member

To fix test_codecs on Windows, you can apply this change for example:

diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index a35de8ad87c..28039ae6cdd 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -35,13 +35,13 @@ def check(input, expect):

 # On small versions of Windows like Windows IoT or Windows Nano Server not all codepages are present
 def is_code_page_present(cp):
-    from ctypes import POINTER, WINFUNCTYPE, WinDLL
+    from ctypes import POINTER, WINFUNCTYPE, WinDLL, Structure
     from ctypes.wintypes import BOOL, BYTE, WCHAR, UINT, DWORD

     MAX_LEADBYTES = 12  # 5 ranges, 2 bytes ea., 0 term.
     MAX_DEFAULTCHAR = 2 # single or double byte
     MAX_PATH = 260
-    class CPINFOEXW(ctypes.Structure):
+    class CPINFOEXW(Structure):
         _fields_ = [("MaxCharSize", UINT),
                     ("DefaultChar", BYTE*MAX_DEFAULTCHAR),
                     ("LeadByte", BYTE*MAX_LEADBYTES),
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@methane
fix windows test
c2a52e3
@hugovk

hugovk commented Apr 28, 2025

Copy link
Copy Markdown
Member

Please could you also list it in https://github.com/python/cpython/blob/main/Doc/deprecations/pending-removal-in-future.rst ?

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@methane
add pending-removal-in-future entry
744eff0
@methane

methane commented Apr 29, 2025

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting change review and removed awaiting changes labels Apr 29, 2025
@bedevere-app

bedevere-app Bot commented Apr 29, 2025

Copy link
Copy Markdown

Thanks for making the requested changes!

@vstinner, @malemburg: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app
bedevere-app Bot requested review from malemburg and vstinner April 29, 2025 01:30
hugovk
hugovk reviewed Apr 29, 2025
View reviewed changes
Comment thread Doc/deprecations/pending-removal-in-future.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

methane and others added 2 commits April 29, 2025 17:23
@methane @hugovk
Apply suggestions from code review
b2dced5
Co-authored-by: Hugo van Kemenade <[email protected]>
@methane @hugovk
Update Doc/deprecations/pending-removal-in-future.rst
c8af536
Co-authored-by: Hugo van Kemenade <[email protected]>
vstinner
vstinner approved these changes Apr 29, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_codecs.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting change review labels Apr 29, 2025
@methane @vstinner
Update Lib/test/test_codecs.py
ce5c94b
Co-authored-by: Victor Stinner <[email protected]>
@hugovk hugovk changed the title gh-133036: deprecate codecs.open gh-133036: Deprecate codecs.open Apr 29, 2025
hugovk
hugovk approved these changes Apr 29, 2025
View reviewed changes
@methane
methane merged commit 4e294f6 into python:main Apr 30, 2025
@methane
methane deleted the deprecate-codecs-open branch April 30, 2025 01:11
@github-project-automation github-project-automation Bot moved this to Done in Codecs and encodings issues Apr 30, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 30, 2025
@vstinner

vstinner commented Apr 30, 2025

Copy link
Copy Markdown
Member

Nicely done, thank you.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@malemburg

malemburg commented Apr 30, 2025

Copy link
Copy Markdown
Member

Thanks for making the requested changes!

@vstinner, @malemburg: please review the changes made to this pull request.

Looks good now. Thanks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Mar 11, 2026
DeprecationWarning: codecs.open() deprecated in Python 3.14 zensical/zensical#427
Closed
fix: replace deprecated codecs.open() with built-in open() (#429) zensical/zensical#428
Merged
DeprecationWarning: codecs.open() deprecated in Python 3.14 zensical/zensical#429
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AA-Turner AA-Turner AA-Turner left review comments
@StanFromIreland StanFromIreland StanFromIreland left review comments
@vstinner vstinner vstinner approved these changes
@hugovk hugovk hugovk approved these changes
@malemburg malemburg Awaiting requested review from malemburg

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

stdlib Standard Library Python modules in the Lib/ directory

Projects

Codecs and encodings issues
Status: Done

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@methane @vstinner @hugovk @malemburg @AA-Turner @StanFromIreland
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.