bpo-33487: improve BZ2File Deprecation and documentation. (GH-6785) · python/cpython@ffa198c (original) (raw)
`@@ -24,6 +24,8 @@
`
24
24
`# Value 2 no longer used
`
25
25
`_MODE_WRITE = 3
`
26
26
``
``
27
`+
_sentinel = object()
`
``
28
+
27
29
``
28
30
`class BZ2File(_compression.BaseStream):
`
29
31
``
`@@ -36,7 +38,7 @@ class BZ2File(_compression.BaseStream):
`
36
38
` returned as bytes, and data to be written should be given as bytes.
`
37
39
` """
`
38
40
``
39
``
`-
def init(self, filename, mode="r", buffering=None, compresslevel=9):
`
``
41
`+
def init(self, filename, mode="r", buffering=_sentinel, compresslevel=9):
`
40
42
`"""Open a bzip2-compressed file.
`
41
43
``
42
44
` 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):
`
47
49
` 'x' for creating exclusively, or 'a' for appending. These can
`
48
50
` equivalently be given as 'rb', 'wb', 'xb', and 'ab'.
`
49
51
``
50
``
`-
buffering is ignored. Its use is deprecated.
`
``
52
`+
buffering is ignored since Python 3.0. Its use is deprecated.
`
51
53
``
52
54
` If mode is 'w', 'x' or 'a', compresslevel can be a number between 1
`
53
55
` 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):
`
63
65
`self._closefp = False
`
64
66
`self._mode = _MODE_CLOSED
`
65
67
``
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)
`
69
73
``
70
74
`if not (1 <= compresslevel <= 9):
`
71
75
`raise ValueError("compresslevel must be between 1 and 9")
`