[New-bugs-announce] [issue34429] On Windows tempfile.TemporaryFile behaves like NamedTemporaryFile

dwich report at bugs.python.org
Sat Aug 18 07:00:17 EDT 2018


New submission from dwich <michal.konvalinka at gmail.com>:

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'.

----------
assignee: docs at python
components: Documentation
messages: 323702
nosy: docs at python, dwich
priority: normal
severity: normal
status: open
title: On Windows tempfile.TemporaryFile behaves like NamedTemporaryFile
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34429>
_______________________________________


More information about the New-bugs-announce mailing list