Skip to content
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

add types to tkinter.filedialog.ask* #5579

Merged
merged 3 commits into from Jun 6, 2021
Merged

add types to tkinter.filedialog.ask* #5579

merged 3 commits into from Jun 6, 2021

Conversation

Akuli
Copy link
Collaborator

@Akuli Akuli commented Jun 6, 2021

Fixes #5571

The options are documented in tk_getOpenFile and tk_getSaveFile manual page (they are both in the same manual page), but to figure out which options actually apply, it turns out to be easiest to give an invalid option:

>>> import tkinter.filedialog
>>> tkinter.filedialog.askopenfilename(lol="wat")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/tkinter/filedialog.py", line 375, in askopenfilename
    return Open(**options).show()
  File "/usr/lib/python3.7/tkinter/commondialog.py", line 43, in show
    s = w.tk.call(self.command, *w._options(self.options))
_tkinter.TclError: bad option "-lol": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, -title, or -typevariable

*, initialdir: StrOrBytesPath | None = ..., mustexist: bool | None = ..., parent: Misc | None = ..., title: str | None = ...
) -> str: ... # can be empty string

# TODO: If someone actually uses these, overload to have the actual return type of open(..., mode)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During several years of tkinter, I haven't seen anyone actually using these functions. They ask the file name, just like askopenfilename() or asksaveasfilename() or askopenfilenames() would, and pass it to the built-in open() function. When using these functions, it's not possible to pass other arguments to open(), such as encoding or errors.

@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2021

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

@srittau srittau merged commit ecafd6f into python:master Jun 6, 2021
@Akuli Akuli deleted the ask branch June 6, 2021 11:26
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.

tkinter filedialog.askdirectory() gives "error: Call to untyped function "askdirectory" in typed context"
2 participants