Skip to content

importlib.resources.as_file is leaving temporary file pointers open #100585

Closed
@samety

Description

@samety

Bug report

importlib.resources.as_file is leaving temporary file pointers open after writing their contents
see _write_contents function in importlib/resources/_common.py

Easy to repeat, just run the test case below with -We
Lib.test.test_importlib.resources.test_resource.ResourceFromZipsTest01.test_as_file_directory

Your environment

  • CPython versions tested on: Python 3.12.0a3+
  • Operating system and architecture: Ubuntu 22.04.1 LTS

I think it just needs to use Path.write_bytes and keep the file pointer closed.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions