gh-133036: Deprecate codecs.open (#133038)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Inada Naoki 2025-04-30 10:11:09 +09:00 committed by GitHub
parent 732d1b0241
commit 4e294f6feb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 58 additions and 37 deletions

View file

@ -884,7 +884,6 @@ class StreamRecoder:
### Shortcuts
def open(filename, mode='r', encoding=None, errors='strict', buffering=-1):
""" Open an encoded file using the given mode and return
a wrapped version providing transparent encoding/decoding.
@ -912,8 +911,11 @@ def open(filename, mode='r', encoding=None, errors='strict', buffering=-1):
.encoding which allows querying the used encoding. This
attribute is only available if an encoding was specified as
parameter.
"""
import warnings
warnings.warn("codecs.open() is deprecated. Use open() instead.",
DeprecationWarning, stacklevel=2)
if encoding is not None and \
'b' not in mode:
# Force opening of the file in binary mode