Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork939
Commitb438c45
committed
Refactor TemporaryFileSwap.__init__ for clarity
This changes the mkstemp call TemporaryFileSwap uses to atomicallycreate (and thus reserve) the temporary file, so that it passesonly a filename (i.e., basename) prefix as `prefix`, and passes allother path components (i.e., the directory) as `dir`. (If theoriginal path has no directory, then `dir` is "" as before.)This makes the mkstemp call *slightly* more idiomatic. This alsomakes it clearer, as it is no longer using `prefix` for somethingthat feels like it should be possible to pass as a Path object.Although mkstemp does not accept a Path as `prefix`, it does (asexpected) accept one as `dir`. However, to keep the code simple,I'm passing str for both. The os.path.split function accepts bothstr and Path (since Python 3.6), and returns str objects, which arenow used for the `dir` and `prefix` arguments to mkstemp.For unusual cases, this may technically not be a refactoring. Forexample, a file_path of "a/b//c" will be split into "a/b" and "c".If the automatically generated temporary file suffix is "xyz", thenthat results in a tmp_file_path of "a/b/cxyz" where "a/b//cxyz"would have been used before. The tmp_file_path attribute of aTemporaryFileSwap object is public (and used in filesystem calls).However, no guarantee has ever been given that the temporary filepath have the original path as an exact string prefix. I believethe slightly weaker relationship I expressed in the recentlyintroduced test_temporary_file_swap -- another file in the samedirectory, named with the original filename with more characters,consisting of equivalent path components in the same order -- hasalways been the intended one.Note that this slight possible variation does not apply to thefile_path attribute. That attribute is always kept exactly as itwas, both in its type and its value, and it always used unmodifiedin calls that access the filesystem.1 parent1ddf953 commitb438c45
1 file changed
+2
-1
lines changedLines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
44 |
| - | |
| 44 | + | |
| 45 | + | |
45 | 46 |
| |
46 | 47 |
| |
47 | 48 |
| |
|
0 commit comments
Comments
(0)