unexpected behavior of tempfile.TemporaryFile() for O_TMPFILE
Open
Nobody has claimed this yet.
stdlib
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Bug report
When O_TMPFILE is available:
tempfile.TemporaryFile(mode='wb')opens withO_RDWRinstead ofO_WRONLY, theopenercallback ignoresmodeargument and always use_bin_openflags_bin_openflagshas bothO_CREATandO_EXCLset, theopenercallback removesO_CREATfrom flags but leaveO_EXCL, this is an undefined behavior according to Linuxopen(2)manpage
Your environment
- CPython versions tested on: 3.10
- Operating system and architecture: Linux x86_64
Linked PRs
- gh-133235
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading tempfile.TemporaryFile and its opener callback, focusing on how the mode argument and _bin_openflags are used when O_TMPFILE is available. Check the Linux open(2) behavior for O_CREAT and O_EXCL, then verify that binary write mode uses the intended access flags without the undefined flag combination.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100