Mailing List Archive

bpo-39693: mention KeyError in tarfile extractfile documentation (GH-18639)
https://github.com/python/cpython/commit/ec42789e6e14f6b6ac13569aeadc13798d7173a8
commit: ec42789e6e14f6b6ac13569aeadc13798d7173a8
branch: master
author: Andrey Doroschenko <dorosch.github.io@yandex.ru>
committer: akuchling <amk@amk.ca>
date: 2020-10-20T10:05:01-04:00
summary:

bpo-39693: mention KeyError in tarfile extractfile documentation (GH-18639)

Co-authored-by: Andrey Darascheka <andrei.daraschenka@leverx.com>

files:
A Misc/NEWS.d/next/Documentation/2020-02-24-09-02-05.bpo-39693.QXw0Fm.rst
M Doc/library/tarfile.rst
M Lib/tarfile.py
M Misc/ACKS

diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst
index cca466b569794..7a114fdf5d54b 100644
--- a/Doc/library/tarfile.rst
+++ b/Doc/library/tarfile.rst
@@ -445,10 +445,11 @@ be finalized; only the internally used file object will be closed. See the

.. method:: TarFile.extractfile(member)

- Extract a member from the archive as a file object. *member* may be a filename
- or a :class:`TarInfo` object. If *member* is a regular file or a link, an
- :class:`io.BufferedReader` object is returned. Otherwise, :const:`None` is
- returned.
+ Extract a member from the archive as a file object. *member* may be
+ a filename or a :class:`TarInfo` object. If *member* is a regular file or
+ a link, an :class:`io.BufferedReader` object is returned. For all other
+ existing members, :const:`None` is returned. If *member* does not appear
+ in the archive, :exc:`KeyError` is raised.

.. versionchanged:: 3.3
Return an :class:`io.BufferedReader` object.
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 1fae29430feff..e42279470dac6 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2093,9 +2093,10 @@ def extract(self, member, path="", set_attrs=True, *, numeric_owner=False):

def extractfile(self, member):
"""Extract a member from the archive as a file object. `member' may be
- a filename or a TarInfo object. If `member' is a regular file or a
- link, an io.BufferedReader object is returned. Otherwise, None is
- returned.
+ a filename or a TarInfo object. If `member' is a regular file or
+ a link, an io.BufferedReader object is returned. For all other
+ existing members, None is returned. If `member' does not appear
+ in the archive, KeyError is raised.
"""
self._check("r")

diff --git a/Misc/ACKS b/Misc/ACKS
index 0aab4567d6ee9..404f70ec87fe2 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1957,5 +1957,6 @@ Gennadiy Zlobin
Doug Zongker
Peter Åstrand
Vlad Emelianov
+Andrey Doroschenko

(Entries should be added in rough alphabetical order by last names)
diff --git a/Misc/NEWS.d/next/Documentation/2020-02-24-09-02-05.bpo-39693.QXw0Fm.rst b/Misc/NEWS.d/next/Documentation/2020-02-24-09-02-05.bpo-39693.QXw0Fm.rst
new file mode 100644
index 0000000000000..86049c536815b
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2020-02-24-09-02-05.bpo-39693.QXw0Fm.rst
@@ -0,0 +1 @@
+Fix tarfile's extractfile documentation

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins
bpo-39693: mention KeyError in tarfile extractfile documentation (GH-18639) [ In reply to ]
https://github.com/python/cpython/commit/b249aeae89f55b9da5cdff082ba271e2b15b7825
commit: b249aeae89f55b9da5cdff082ba271e2b15b7825
branch: 3.9
author: Miss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>
committer: akuchling <amk@amk.ca>
date: 2020-10-20T10:31:03-04:00
summary:

bpo-39693: mention KeyError in tarfile extractfile documentation (GH-18639)

Co-authored-by: Andrey Darascheka <andrei.daraschenka@leverx.com>
(cherry picked from commit ec42789e6e14f6b6ac13569aeadc13798d7173a8)

Closes bpo-39693.

files:
A Misc/NEWS.d/next/Documentation/2020-02-24-09-02-05.bpo-39693.QXw0Fm.rst
M Doc/library/tarfile.rst
M Lib/tarfile.py
M Misc/ACKS

diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst
index cca466b569794..7a114fdf5d54b 100644
--- a/Doc/library/tarfile.rst
+++ b/Doc/library/tarfile.rst
@@ -445,10 +445,11 @@ be finalized; only the internally used file object will be closed. See the

.. method:: TarFile.extractfile(member)

- Extract a member from the archive as a file object. *member* may be a filename
- or a :class:`TarInfo` object. If *member* is a regular file or a link, an
- :class:`io.BufferedReader` object is returned. Otherwise, :const:`None` is
- returned.
+ Extract a member from the archive as a file object. *member* may be
+ a filename or a :class:`TarInfo` object. If *member* is a regular file or
+ a link, an :class:`io.BufferedReader` object is returned. For all other
+ existing members, :const:`None` is returned. If *member* does not appear
+ in the archive, :exc:`KeyError` is raised.

.. versionchanged:: 3.3
Return an :class:`io.BufferedReader` object.
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 6769066cabd6f..62a6d9d120ffa 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2091,9 +2091,10 @@ def extract(self, member, path="", set_attrs=True, *, numeric_owner=False):

def extractfile(self, member):
"""Extract a member from the archive as a file object. `member' may be
- a filename or a TarInfo object. If `member' is a regular file or a
- link, an io.BufferedReader object is returned. Otherwise, None is
- returned.
+ a filename or a TarInfo object. If `member' is a regular file or
+ a link, an io.BufferedReader object is returned. For all other
+ existing members, None is returned. If `member' does not appear
+ in the archive, KeyError is raised.
"""
self._check("r")

diff --git a/Misc/ACKS b/Misc/ACKS
index 2aa9a9de93703..021df26426e36 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1941,5 +1941,6 @@ Gennadiy Zlobin
Doug Zongker
Peter Åstrand
Vlad Emelianov
+Andrey Doroschenko

(Entries should be added in rough alphabetical order by last names)
diff --git a/Misc/NEWS.d/next/Documentation/2020-02-24-09-02-05.bpo-39693.QXw0Fm.rst b/Misc/NEWS.d/next/Documentation/2020-02-24-09-02-05.bpo-39693.QXw0Fm.rst
new file mode 100644
index 0000000000000..86049c536815b
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2020-02-24-09-02-05.bpo-39693.QXw0Fm.rst
@@ -0,0 +1 @@
+Fix tarfile's extractfile documentation

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins