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
[doc] On Windows tempfile.TemporaryFile behaves like NamedTemporaryFile #78610
Comments
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 |
3.4 and 3.5 only get security fixes. Anyone preparing PR should check that behavior and doc is same on master; I just assumed in setting Versions header. In the proposed text, it is not clear that 'non' applies to cygwin also. Instead: "On platforms that are neither Posix nor Cygwin, ..." |
The docs and the code are the same now. I would add just the first half of the suggested sentence: "On platforms that are neither Posix nor Cygwin, TemporaryFile behaves exactly like NamedTemporaryFile". |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: