Skip to content

Deprecate tkinter.filedialog.askopenfiles() #152638

Description

@serhiy-storchaka

Feature or enhancement

tkinter.filedialog.askopenfiles() returns a list of already-open file objects, which is inherently unsafe:

  • If opening one of the files fails, the files already opened are leaked — there is no way to build the result without this risk.
  • A list of open files cannot be used in a with statement. The caller must iterate and close them, and on an exception in the loop must close both the already-processed and the not-yet-processed files, which is hard to get right.
  • The number of open file descriptors is limited, so opening all the files at once may not even be possible.

The safe and simple alternative is to iterate over the names returned by askopenfilenames() and open them one by one, ideally with a with statement.

Proposal: deprecate askopenfiles() in 3.16 and remove it in 3.18.

The single-file askopenfile() and asksaveasfile() are not affected — they return a single file object that the caller can use directly.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions