bpo-39357: Remove buffering parameter of bz2.BZ2File (GH-18028)
Remove the buffering parameter of bz2.BZ2File. Since Python 3.0, it was ignored and using it was emitting a DeprecationWarning. Pass an open file object to control how the file is opened. The compresslevel parameter becomes keyword-only.
This commit is contained in:
parent
c5b79003f5
commit
9baf242fc7
|
@ -65,7 +65,7 @@ All of the classes in this module may safely be accessed from multiple threads.
|
||||||
Accepts a :term:`path-like object`.
|
Accepts a :term:`path-like object`.
|
||||||
|
|
||||||
|
|
||||||
.. class:: BZ2File(filename, mode='r', buffering=None, compresslevel=9)
|
.. class:: BZ2File(filename, mode='r', *, compresslevel=9)
|
||||||
|
|
||||||
Open a bzip2-compressed file in binary mode.
|
Open a bzip2-compressed file in binary mode.
|
||||||
|
|
||||||
|
@ -81,8 +81,6 @@ All of the classes in this module may safely be accessed from multiple threads.
|
||||||
If *filename* is a file object (rather than an actual file name), a mode of
|
If *filename* is a file object (rather than an actual file name), a mode of
|
||||||
``'w'`` does not truncate the file, and is instead equivalent to ``'a'``.
|
``'w'`` does not truncate the file, and is instead equivalent to ``'a'``.
|
||||||
|
|
||||||
The *buffering* argument is ignored. Its use is deprecated since Python 3.0.
|
|
||||||
|
|
||||||
If *mode* is ``'w'`` or ``'a'``, *compresslevel* can be an integer between
|
If *mode* is ``'w'`` or ``'a'``, *compresslevel* can be an integer between
|
||||||
``1`` and ``9`` specifying the level of compression: ``1`` produces the
|
``1`` and ``9`` specifying the level of compression: ``1`` produces the
|
||||||
least compression, and ``9`` (default) produces the most compression.
|
least compression, and ``9`` (default) produces the most compression.
|
||||||
|
@ -110,9 +108,6 @@ All of the classes in this module may safely be accessed from multiple threads.
|
||||||
.. versionadded:: 3.3
|
.. versionadded:: 3.3
|
||||||
|
|
||||||
|
|
||||||
.. deprecated:: 3.0
|
|
||||||
The keyword argument *buffering* was deprecated and is now ignored.
|
|
||||||
|
|
||||||
.. versionchanged:: 3.1
|
.. versionchanged:: 3.1
|
||||||
Support for the :keyword:`with` statement was added.
|
Support for the :keyword:`with` statement was added.
|
||||||
|
|
||||||
|
@ -138,6 +133,13 @@ All of the classes in this module may safely be accessed from multiple threads.
|
||||||
.. versionchanged:: 3.6
|
.. versionchanged:: 3.6
|
||||||
Accepts a :term:`path-like object`.
|
Accepts a :term:`path-like object`.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.9
|
||||||
|
The *buffering* parameter has been removed. It was ignored and deprecated
|
||||||
|
since Python 3.0. Pass an open file object to control how the file is
|
||||||
|
opened.
|
||||||
|
|
||||||
|
The *compresslevel* parameter became keyword-only.
|
||||||
|
|
||||||
|
|
||||||
Incremental (de)compression
|
Incremental (de)compression
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
|
@ -420,6 +420,12 @@ Removed
|
||||||
3.5 (:issue:`22486`): use :func:`math.gcd` instead.
|
3.5 (:issue:`22486`): use :func:`math.gcd` instead.
|
||||||
(Contributed by Victor Stinner in :issue:`39350`.)
|
(Contributed by Victor Stinner in :issue:`39350`.)
|
||||||
|
|
||||||
|
* The *buffering* parameter of :class:`bz2.BZ2File` has been removed. Since
|
||||||
|
Python 3.0, it was ignored and using it was emitting
|
||||||
|
:exc:`DeprecationWarning`. Pass an open file object to control how the file
|
||||||
|
is opened.
|
||||||
|
(Contributed by Victor Stinner in :issue:`39357`.)
|
||||||
|
|
||||||
|
|
||||||
Porting to Python 3.9
|
Porting to Python 3.9
|
||||||
=====================
|
=====================
|
||||||
|
@ -451,6 +457,10 @@ Changes in the Python API
|
||||||
:data:`~errno.EBADF` error.
|
:data:`~errno.EBADF` error.
|
||||||
(Contributed by Victor Stinner in :issue:`39239`.)
|
(Contributed by Victor Stinner in :issue:`39239`.)
|
||||||
|
|
||||||
|
* The *compresslevel* parameter of :class:`bz2.BZ2File` became keyword-only,
|
||||||
|
since the *buffering* parameter has been removed.
|
||||||
|
(Contributed by Victor Stinner in :issue:`39357`.)
|
||||||
|
|
||||||
|
|
||||||
CPython bytecode changes
|
CPython bytecode changes
|
||||||
------------------------
|
------------------------
|
||||||
|
|
10
Lib/bz2.py
10
Lib/bz2.py
|
@ -24,8 +24,6 @@ _MODE_READ = 1
|
||||||
# Value 2 no longer used
|
# Value 2 no longer used
|
||||||
_MODE_WRITE = 3
|
_MODE_WRITE = 3
|
||||||
|
|
||||||
_sentinel = object()
|
|
||||||
|
|
||||||
|
|
||||||
class BZ2File(_compression.BaseStream):
|
class BZ2File(_compression.BaseStream):
|
||||||
|
|
||||||
|
@ -38,7 +36,7 @@ class BZ2File(_compression.BaseStream):
|
||||||
returned as bytes, and data to be written should be given as bytes.
|
returned as bytes, and data to be written should be given as bytes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, filename, mode="r", buffering=_sentinel, compresslevel=9):
|
def __init__(self, filename, mode="r", *, compresslevel=9):
|
||||||
"""Open a bzip2-compressed file.
|
"""Open a bzip2-compressed file.
|
||||||
|
|
||||||
If filename is a str, bytes, or PathLike object, it gives the
|
If filename is a str, bytes, or PathLike object, it gives the
|
||||||
|
@ -65,12 +63,6 @@ class BZ2File(_compression.BaseStream):
|
||||||
self._closefp = False
|
self._closefp = False
|
||||||
self._mode = _MODE_CLOSED
|
self._mode = _MODE_CLOSED
|
||||||
|
|
||||||
if buffering is not _sentinel:
|
|
||||||
warnings.warn("Use of 'buffering' argument is deprecated and ignored "
|
|
||||||
"since Python 3.0.",
|
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=2)
|
|
||||||
|
|
||||||
if not (1 <= compresslevel <= 9):
|
if not (1 <= compresslevel <= 9):
|
||||||
raise ValueError("compresslevel must be between 1 and 9")
|
raise ValueError("compresslevel must be between 1 and 9")
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,9 @@ class BZ2FileTest(BaseTest):
|
||||||
self.assertRaises(ValueError, BZ2File, os.devnull, compresslevel=0)
|
self.assertRaises(ValueError, BZ2File, os.devnull, compresslevel=0)
|
||||||
self.assertRaises(ValueError, BZ2File, os.devnull, compresslevel=10)
|
self.assertRaises(ValueError, BZ2File, os.devnull, compresslevel=10)
|
||||||
|
|
||||||
|
# compresslevel is keyword-only
|
||||||
|
self.assertRaises(TypeError, BZ2File, os.devnull, "r", 3)
|
||||||
|
|
||||||
def testRead(self):
|
def testRead(self):
|
||||||
self.createTempFile()
|
self.createTempFile()
|
||||||
with BZ2File(self.filename) as bz2f:
|
with BZ2File(self.filename) as bz2f:
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Remove the *buffering* parameter of :class:`bz2.BZ2File`. Since Python 3.0, it
|
||||||
|
was ignored and using it was emitting :exc:`DeprecationWarning`. Pass an open
|
||||||
|
file object, to control how the file is opened. The *compresslevel* parameter
|
||||||
|
becomes keyword-only.
|
Loading…
Reference in New Issue