-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Simplify new_tmp_dir #13273
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
Simplify new_tmp_dir #13273
Conversation
dfangl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for adding proper typing as well!
| folder = new_tmp_file(dir=dir) | ||
| rm_rf(folder) | ||
| mkdir(folder) | ||
| def new_tmp_dir(dir: str | None = None, mode: int = 0o777) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: a docstring explaining some of the behavior here would be nice as well. Totally optional though!
Motivation
This PR attempts to simplify the logic of the
new_tmp_dirutility functions.The original implementation uses
tempfile.mkstempand first closes the file descriptor of the created file, then removes the created directory, and finally, re-creates it.The new implementation relies on
tempfile.mkdtemp. It also preserves the original behavior by changing the permissions (tempfile.mkdtempwould come with0o700whilemkdirhas0o777).Changes
new_tmp_dirfunction withtempfile.mkdtemp, as explained above.