Skip to content

Fix return types in tkinter.filedialog - #16689

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

Fix return types in tkinter.filedialog

Closes #16637

Description

In tkinter.filedialog, functions such as askdirectory(), askopenfilename(), and asksaveasfilename() return an empty tuple () when the dialog is dismissed or canceled without selecting anything (depending on the Tk/platform implementation), whereas previously the stub only typed str.

This PR updates the return type of:

  • asksaveasfilename() -> str | tuple[()]
  • askopenfilename() -> str | tuple[()]
  • askdirectory() -> str | tuple[()]

Validation

  • mypy_test.py stdlib/tkinter/filedialog.pyi passed cleanly across all supported Python versions (3.10 - 3.15).
  • pyright_test.py stdlib/tkinter/filedialog.pyi passed with 0 errors and 0 warnings.

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

Still a dupe with #16642.

@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