Skip to content

Docs for urllib.request.urlcleanup does not mention that it will uninstall openers installed with urllib.request.install_opener #102591

Closed

Description

@aucampia

Documentation

urllib.request.install_opener sets urllib.request._opener to the supplied value:

def install_opener(opener):
global _opener
_opener = opener

And urllib.request.urlcleanup sets urllib.requests._opener to None, thus essentially uninstalling any previously installed global opener:

def urlcleanup():
"""Clean up temporary files from urlretrieve calls."""
for temp_file in _url_tempfiles:
try:
os.unlink(temp_file)
except OSError:
pass
del _url_tempfiles[:]
global _opener
if _opener:
_opener = None

However, this uninstallation of a previously installed global opener is not documented.

If the uninstallation of openers installed with install_opener is intended, then it would be best to document it in urlcleanup, and if it is not intended this should be a bug instead of a doc issue.

Linked PRs

Activity

  1. arhadthedev commented on Apr 2, 2023

    @arhadthedev
    Member

    @orsenthil (as an urllib expert)

  2. orsenthil commented on Apr 3, 2023

    @orsenthil
    Member

    However, this uninstallation of a previously installed global opener is not documented.

    Please go ahead and submit a patch. Thank you.

  3. Taeknology commented on Jul 11, 2026

    @Taeknology
    Contributor

    Hi, I’d like to work on this documentation issue. I plan to update the urlcleanup() documentation to mention that it also resets the default global opener installed by install_opener(). I expect to submit a small documentation-only PR within the next few days.

  4. moved this from Todo to In Progress in Urllib issueson Jul 11, 2026
  5. added a commit that references this issue on Jul 11, 2026
  6. added a commit that references this issue on Jul 11, 2026
  7. moved this from In Progress to Done in Urllib issueson Jul 11, 2026
  8. added 3 commits that reference this issue on Jul 11, 2026
  9. orsenthil commented on Jul 11, 2026

    @orsenthil
    Member

    Thanks for the patch, @Taeknology .

  10. self-assigned this
    on Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dir

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions