Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
370138ba
Commit
370138ba
authored
Sep 09, 2019
by
Anthony Sottile
Committed by
Zachary Ware
Sep 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-35803: Document and test dir=PathLike for tempfile (GH-11644)
Co-Authored-By:
Ammar Askar
<
ammar_askar@hotmail.com
>
parent
9488a528
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
2 deletions
+22
-2
Doc/library/tempfile.rst
Doc/library/tempfile.rst
+6
-0
Lib/test/test_tempfile.py
Lib/test/test_tempfile.py
+14
-2
Misc/NEWS.d/next/Documentation/2019-01-21-14-30-59.bpo-35803.yae6Lq.rst
...xt/Documentation/2019-01-21-14-30-59.bpo-35803.yae6Lq.rst
+2
-0
No files found.
Doc/library/tempfile.rst
View file @
370138ba
...
...
@@ -191,6 +191,9 @@ The module defines the following user-callable items:
*suffix* and *prefix* now accept and default to ``None`` to cause
an appropriate default value to be used.
.. versionchanged:: 3.6
The *dir* parameter now accepts a :term:`path-like object`.
.. function:: mkdtemp(suffix=None, prefix=None, dir=None)
...
...
@@ -214,6 +217,9 @@ The module defines the following user-callable items:
*suffix* and *prefix* now accept and default to ``None`` to cause
an appropriate default value to be used.
.. versionchanged:: 3.6
The *dir* parameter now accepts a :term:`path-like object`.
.. function:: gettempdir()
...
...
Lib/test/test_tempfile.py
View file @
370138ba
...
...
@@ -3,6 +3,7 @@ import tempfile
import
errno
import
io
import
os
import
pathlib
import
signal
import
sys
import
re
...
...
@@ -56,6 +57,9 @@ class TestLowLevelInternals(unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
tempfile
.
_infer_return_type
(
b''
,
None
,
''
)
def
test_infer_return_type_pathlib
(
self
):
self
.
assertIs
(
str
,
tempfile
.
_infer_return_type
(
pathlib
.
Path
(
'/'
)))
# Common functionality.
...
...
@@ -79,8 +83,13 @@ class BaseTestCase(unittest.TestCase):
nsuf
=
nbase
[
len
(
nbase
)
-
len
(
suf
):]
if
dir
is
not
None
:
self
.
assertIs
(
type
(
name
),
str
if
type
(
dir
)
is
str
else
bytes
,
"unexpected return type"
)
self
.
assertIs
(
type
(
name
),
str
if
type
(
dir
)
is
str
or
isinstance
(
dir
,
os
.
PathLike
)
else
bytes
,
"unexpected return type"
,
)
if
pre
is
not
None
:
self
.
assertIs
(
type
(
name
),
str
if
type
(
pre
)
is
str
else
bytes
,
"unexpected return type"
)
...
...
@@ -425,6 +434,7 @@ class TestMkstempInner(TestBadTempdir, BaseTestCase):
dir
=
tempfile
.
mkdtemp
()
try
:
self
.
do_create
(
dir
=
dir
).
write
(
b"blat"
)
self
.
do_create
(
dir
=
pathlib
.
Path
(
dir
)).
write
(
b"blat"
)
finally
:
os
.
rmdir
(
dir
)
...
...
@@ -659,6 +669,7 @@ class TestMkstemp(BaseTestCase):
dir
=
tempfile
.
mkdtemp
()
try
:
self
.
do_create
(
dir
=
dir
)
self
.
do_create
(
dir
=
pathlib
.
Path
(
dir
))
finally
:
os
.
rmdir
(
dir
)
...
...
@@ -728,6 +739,7 @@ class TestMkdtemp(TestBadTempdir, BaseTestCase):
dir
=
tempfile
.
mkdtemp
()
try
:
os
.
rmdir
(
self
.
do_create
(
dir
=
dir
))
os
.
rmdir
(
self
.
do_create
(
dir
=
pathlib
.
Path
(
dir
)))
finally
:
os
.
rmdir
(
dir
)
...
...
Misc/NEWS.d/next/Documentation/2019-01-21-14-30-59.bpo-35803.yae6Lq.rst
0 → 100644
View file @
370138ba
Document and test that ``tempfile`` functions may accept a
:term:`path-like object` for the ``dir`` argument. Patch by Anthony Sottile.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment