gh-103878: Return a consistent empty value from cancelled file dialogs#152435
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-103878: Return a consistent empty value from cancelled file dialogs#152435serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
…dialogs On cancellation Tcl may report the empty result as '', () or b'' depending on the platform and Tk version. Normalize it so that askopenfilename(), asksaveasfilename() and askdirectory() always return '' and askopenfilenames() always returns (). Open._fixresult() now distinguishes single from multiple results by the 'multiple' option rather than the result type. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a native file dialog is cancelled, Tcl reports the empty result as
'', an empty tuple, orb''depending on the platform and Tk version (the value comes back with whatever internal type the empty Tcl object happened to have). As a resultaskdirectory()returns()on some platforms and''on others, andaskopenfilename()/asksaveasfilename()are similarly inconsistent.This normalizes the cancelled result per the value the function normally returns:
askopenfilename(),asksaveasfilename(),askdirectory()) always return'';askopenfilenames()always returns an empty tuple.askopenfile()/asksaveasfile()keep returningNone, since an empty value of a file object's "type" does not exist.Open._fixresult()now distinguishes single from multiple results by themultipleoption rather than by the result type, so an empty single result (an empty tuple from Tcl) is no longer mistaken for a multiple selection. This avoids the issue with PR #111195, which collapsed the legitimate empty tuple returned byaskopenfilenames().Since this changes behavior, it targets the main branch only. The documentation half of the issue was handled separately in #152429.