Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffa198c

Browse files
Carreaugpshead
authored andcommitted
bpo-33487: improve BZ2File Deprecation and documentation. (GH-6785)
Emit warning when None passed explicitly, list Python version since deprecation in warning message and docs.
1 parent f019579 commit ffa198c

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Doc/library/bz2.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ All of the classes in this module may safely be accessed from multiple threads.
8181
If *filename* is a file object (rather than an actual file name), a mode of
8282
``'w'`` does not truncate the file, and is instead equivalent to ``'a'``.
8383

84-
The *buffering* argument is ignored. Its use is deprecated.
84+
The *buffering* argument is ignored. Its use is deprecated since Python 3.0.
8585

8686
If *mode* is ``'w'`` or ``'a'``, *compresslevel* can be a number between
8787
``1`` and ``9`` specifying the level of compression: ``1`` produces the
@@ -109,6 +109,10 @@ All of the classes in this module may safely be accessed from multiple threads.
109109

110110
.. versionadded:: 3.3
111111

112+
113+
.. deprecated:: 3.0
114+
The keyword argument *buffering* was deprecated and is now ignored.
115+
112116
.. versionchanged:: 3.1
113117
Support for the :keyword:`with` statement was added.
114118

Lib/bz2.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
# Value 2 no longer used
2525
_MODE_WRITE = 3
2626

27+
_sentinel = object()
28+
2729

2830
class BZ2File(_compression.BaseStream):
2931

@@ -36,7 +38,7 @@ class BZ2File(_compression.BaseStream):
3638
returned as bytes, and data to be written should be given as bytes.
3739
"""
3840

39-
def __init__(self, filename, mode="r", buffering=None, compresslevel=9):
41+
def __init__(self, filename, mode="r", buffering=_sentinel, compresslevel=9):
4042
"""Open a bzip2-compressed file.
4143
4244
If filename is a str, bytes, or PathLike object, it gives the
@@ -47,7 +49,7 @@ def __init__(self, filename, mode="r", buffering=None, compresslevel=9):
4749
'x' for creating exclusively, or 'a' for appending. These can
4850
equivalently be given as 'rb', 'wb', 'xb', and 'ab'.
4951
50-
buffering is ignored. Its use is deprecated.
52+
buffering is ignored since Python 3.0. Its use is deprecated.
5153
5254
If mode is 'w', 'x' or 'a', compresslevel can be a number between 1
5355
and 9 specifying the level of compression: 1 produces the least
@@ -63,9 +65,11 @@ def __init__(self, filename, mode="r", buffering=None, compresslevel=9):
6365
self._closefp = False
6466
self._mode = _MODE_CLOSED
6567

66-
if buffering is not None:
67-
warnings.warn("Use of 'buffering' argument is deprecated",
68-
DeprecationWarning)
68+
if buffering is not _sentinel:
69+
warnings.warn("Use of 'buffering' argument is deprecated and ignored"
70+
"since Python 3.0.",
71+
DeprecationWarning,
72+
stacklevel=2)
6973

7074
if not (1 <= compresslevel <= 9):
7175
raise ValueError("compresslevel must be between 1 and 9")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BZ2file now emit a DeprecationWarning when buffering=None is passed, the
2+
deprecation message and documentation also now explicitely state it is
3+
deprecated since 3.0.

0 commit comments

Comments
 (0)