Message323702
On Windows tempfile.TemporaryFile() accepts delete attribute. On Linux TemporaryFile() raises TypeError if delete attribute is used.
In tempfile.py source is the code below which means that on Windows TemporaryFile behaves like NamedTemporaryFile. I suppose the code should not be changed but the behaviour should be mentioned in documentation.
if _os.name != 'posix' or _os.sys.platform == 'cygwin':
# On non-POSIX and Cygwin systems, assume that we cannot unlink a file
# while it is open.
TemporaryFile = NamedTemporaryFile
Steps to reproduce:
>>> import tempfile
>>> tf = tempfile.TemporaryFile(delete=False)
On Linux Python throws TypeError:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: TemporaryFile() got an unexpected keyword argument 'delete'
On Windows Python does not throw TypeError because on Windows TemporaryFile is in fact NamedTemporaryFile which accepts delete attribute.
Tested on all these versions: 3.7.0 64 bit, 3.6.5 32 bit, 3.5.4 32 bit, 3.4.4 32 bit, 2.7.15 32 bit
Proposed text to tempfile.TemporaryFile documentation:
On non POSIX or Cygwin platforms TemporaryFile behaves exacly like NamedTemporaryFile including the fact that TemporaryFile accepts delete attribute and does not raise
TypeError: TemporaryFile() got an unexpected keyword argument 'delete'. |
|
Date |
User |
Action |
Args |
2018-08-18 11:00:17 | dwich | set | recipients:
+ dwich, docs@python |
2018-08-18 11:00:17 | dwich | set | messageid: <1534590017.91.0.56676864532.issue34429@psf.upfronthosting.co.za> |
2018-08-18 11:00:17 | dwich | link | issue34429 messages |
2018-08-18 11:00:17 | dwich | create | |
|