-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
bpo-35803: Document and test dir=PathLike for tempfile #11644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import errno | ||
| import io | ||
| import os | ||
| import pathlib | ||
| import signal | ||
| import sys | ||
| import re | ||
|
|
@@ -61,6 +62,9 @@ def test_infer_return_type_multiples_and_none(self): | |
| 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. | ||
|
|
||
|
|
@@ -84,8 +88,13 @@ def nameCheck(self, name, dir, pre, suf): | |
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe break this up to it's own line since its getting a bid crowded as a ternary |
||
| bytes, | ||
| "unexpected return type", | ||
| ) | ||
| if pre is not None: | ||
| self.assertIs(type(name), str if type(pre) is str else bytes, | ||
| "unexpected return type") | ||
|
|
@@ -430,6 +439,7 @@ def test_choose_directory(self): | |
| 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) | ||
|
|
||
|
|
@@ -666,6 +676,7 @@ def test_choose_directory(self): | |
| dir = tempfile.mkdtemp() | ||
| try: | ||
| self.do_create(dir=dir) | ||
| self.do_create(dir=pathlib.Path(dir)) | ||
| finally: | ||
| os.rmdir(dir) | ||
|
|
||
|
|
@@ -735,6 +746,7 @@ def test_choose_directory(self): | |
| dir = tempfile.mkdtemp() | ||
| try: | ||
| os.rmdir(self.do_create(dir=dir)) | ||
| os.rmdir(self.do_create(dir=pathlib.Path(dir))) | ||
| finally: | ||
| os.rmdir(dir) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Document and test that ``tempfile`` functions may take a ``dir`` which | ||
asottile marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| is a :term:`path-like object`. Patch by Anthony Sottile. | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a difference between current code and
isinstance(dir, (str, os.PathLike))?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ever so slightly. The current code is "type is exactly
str", my patch is "type is exactlystror it implementsPathLike", your suggestion is "stror any subclass ofstror implementsPathLike"