Repository navigation
[tkinter] Fix return types in tkinter.filedialog to allow empty tuples - #16684
Closed
hrithiksaini99 wants to merge 1 commit into
Closed
hrithiksaini99 wants to merge 1 commit into
hrithiksaini99 wants to merge 1 commit into
Conversation
Update return types of asksaveasfilename, askopenfilename, and askdirectory to str | tuple[()] to accommodate empty tuples returned on cancellation. Closes: python#16637
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Collaborator
|
Dupe |
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 dialogs in
tkinter.filedialog(askopenfilename,asksaveasfilename,askdirectory) are closed or cancelled without selecting a path, Tcl/Tk can return an empty tuple()(or empty string""depending on platform/Tk version).The stubs currently declare only
str, which causes type checkers to reject checks against()or branches handling empty tuple returns.This PR updates the return types of:
asksaveasfilename:str | tuple[()]askopenfilename:str | tuple[()]askdirectory:str | tuple[()]Also adds corresponding test cases to
stdlib/@tests/test_cases/check_tkinter.py.Closes #16637.
Verification
pre-commit run --files stdlib/tkinter/filedialog.pyi stdlib/@tests/test_cases/check_tkinter.py(Passed)tests/check_typeshed_structure.py(Passed)tests/pyright_test.py stdlib/tkinter/filedialog.pyi(Passed)tests/mypy_test.py stdlib/tkinter/filedialog.pyiacross all Python versions 3.10-3.15 (Passed)tests/regr_test.py stdlib(Passed)