Skip to content

[tkinter] Fix return types in tkinter.filedialog to allow empty tuples - #16684

Closed
hrithiksaini99 wants to merge 1 commit into
python:mainfrom
hrithiksaini99:tkinter-filedialog-return-types
Closed

hrithiksaini99 wants to merge 1 commit into
python:mainfrom
hrithiksaini99:tkinter-filedialog-return-types

Conversation

@hrithiksaini99

Copy link
Copy Markdown
Contributor

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.pyi across all Python versions 3.10-3.15 (Passed)
  • tests/regr_test.py stdlib (Passed)

Update return types of asksaveasfilename, askopenfilename, and askdirectory
to str | tuple[()] to accommodate empty tuples returned on cancellation.

Closes: python#16637
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau

srittau commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Dupe

@srittau srittau closed this Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return types in tkinter.filedialog

2 participants