Skip to content

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Releases before 0.2.0 kept no changelog.

Unreleased

0.2.1 - 2026-10-19

Fixed

  • A patcher for a submodule (urllib.request) could not reach it as an attribute of its package: the import system binds it only after the loader returns, so import urllib.request; urllib.request.X in the patcher's module failed ("cannot access submodule ... most likely due to a circular import") and the patch was skipped. The submodule is now bound on its package before its patchers run.

0.2.0 - 2026-10-19

Added

  • Hooks registered by entry point: a distribution declares [project.entry-points.importpatch] with <module> = "<dotted.patcher>". A function is called with the module right after it is imported; a module is called through its importpatch(name, module).
  • The wheel ships importpatch.pth: installing the package activates the hook in every interpreter of the environment, and uninstalling removes it. IMPORTPATCH_DISABLE=1 turns it off.
  • A module already imported when its hook is registered is patched at once.
  • importpatch.patches() lists the registry; importpatch.__version__.
  • Configuration files named pyimportpatch.cfg: a [module] section per module to patch, one patcher per line, patcher = false to disable one (an entry point's included). A system file (/etc/pyimportpatch.cfg, %PROGRAMDATA% on Windows, or $IMPORTPATCH_SYSTEM_CONFIG) and then the user's ($XDG_CONFIG_HOME, %APPDATA% on Windows, or $IMPORTPATCH_CONFIG) are applied over the entry points. Each variable may list several files separated by os.pathsep.
  • MIT license.

Changed

  • Modules are found by Python's own finders and their loader is wrapped, so packages, zip archives and other importable modules are patched; 0.1 found only .py files and package directories on sys.path.
  • A patcher that is missing or raises is logged on the importpatch logger and skipped; it no longer fails the import of the module it patches (a missing package did) and is no longer ignored silently. A configuration line that cannot be read is logged with the file and line number.
  • .pymodpatch.json (in the working directory, site-packages or ~) is no longer read; pyimportpatch.cfg replaces it, and the user file is not read under python -I or -s.
  • rm(target, patcher) is remove(target, patcher=None); remove(target) removes every patcher (in 0.1, rm(target, None) raised KeyError).
  • Packaged with pyproject.toml; the source distribution builds (0.1.3's lacked the VERSION file it read). Requires Python 3.9 or later.

Removed

  • python -m importpatch enable / disable: installing and uninstalling do this.
  • MODULES_TO_PATCH: use patches(), add() and remove().

Fixed

  • After enable, every interpreter printed NameError: name 'file' is not defined at exit.