-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-129534: Fix asksaveasfilename not appending file extension when none is provided #129682
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
Changes from 1 commit
1b9d3cc
24db516
c4366df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -385,9 +385,27 @@ def askopenfilename(**options): | |
|
|
||
|
|
||
| def asksaveasfilename(**options): | ||
| "Ask for a filename to save as" | ||
| """Ask for a filename to save as""" | ||
|
|
||
| # If no default extension is provided, set it to the first filetype | ||
| if "defaultextension" not in options: | ||
| filetypes = options.get("filetypes") | ||
| if filetypes: | ||
| first_ext = filetypes[0][1] # Get "*.txt" from ("Text files", "*.txt") | ||
| if first_ext.startswith("*"): | ||
| options["defaultextension"] = first_ext[1:] # ".txt" | ||
|
|
||
| filename = SaveAs(**options).show() | ||
|
|
||
| # Append extension if missing | ||
| if filename and '.' not in filename: | ||
| ext = options.get("defaultextension", "") | ||
| if ext and not filename.endswith(ext): | ||
| filename += ext | ||
|
||
|
|
||
| return filename | ||
|
|
||
|
|
||
| return SaveAs(**options).show() | ||
|
|
||
|
|
||
| def askopenfilenames(**options): | ||
|
|
||

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.
This will work incorrectly in cases like "-.txt" or "*.a[0-9]". It is easier to just specify an unambiguous
defaultextensionargument in your code.This change also removes possibility to enter extensionless name, which may be desirable.