-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
In the tempfile module, TemporaryFile is defined as an alias for NamedTemporaryFile for non-posix systems:
Lines 620 to 623 in 0c29f83
| if _os.name != 'posix' or _sys.platform == 'cygwin': | |
| # On non-POSIX and Cygwin systems, assume that we cannot unlink a file | |
| # while it is open. | |
| TemporaryFile = NamedTemporaryFile |
That means that in, e.g. Linux, the args are:
def TemporaryFile(mode='w+b', buffering=-1, encoding=None,
newline=None, suffix=None, prefix=None,
dir=None, *, errors=None)while in, e.g. Windows, they are:
def NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None,
newline=None, suffix=None, prefix=None,
dir=None, delete=True, *, errors=None,
delete_on_close=True)Static checkers such as VSCode pick up on this and let me write code like this:
with TemporaryFile(delete=False) as tmp:
...and it will run fine in Windows but not anywhere else.
I believe TemporaryFile should not just be a simple alias for non-posix systems; it can certainly wrap NamedTemporaryFile, but should have the exact same signature across platforms.
CPython versions tested on:
3.12
Operating systems tested on:
Linux, Windows
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error