Skip to content

Skip instance updates when an autoreload class is unchanged - #15423

Open
Cherith1222 wants to merge 1 commit into
ipython:mainfrom
Cherith1222:fix/14984-autoreload-partial
Open

Cherith1222 wants to merge 1 commit into
ipython:mainfrom
Cherith1222:fix/14984-autoreload-partial

Conversation

@Cherith1222

Copy link
Copy Markdown

Fixes #14984.

%autoreload called update_instances on an imported type such as functools.partial even when the reload left that type as the same object. Those instances reject __class__ assignment, so the reload raised TypeError and stopped. If the old and new class objects are identical, instance migration is now skipped. A class that was actually replaced still has its instances moved.

This is a bug fix, not a new feature or a backwards-incompatible change, so there is no file under docs/source/whatsnew/pr/.

Tests, on Windows with Python 3.13.3, via Resource Sentinel (1 CPU, 1.5 GiB, 1 I/O):

  • With IPython/extensions/autoreload.py checked out at main, test_update_instances_skips_unchanged_imported_type failed with TypeError: __class__ assignment only supported for mutable types or ModuleType subclasses.
  • On this commit the same test passed (1 passed, 24 deselected).
  • ruff check still reports four existing F541 findings in tests/test_zzz_autoreload.py (lines 475, 477, 506, and 533). They are not in this diff and were left as they are. ruff format also wants to reflow other existing lines in those two files. The lines added here were not part of that.

Not run: the full suite, and anything other than Windows.

This patch was drafted with AI assistance (Cursor).

Reloading a module that imported functools.partial called update_instances on the same type and raised TypeError. A class that was actually replaced still migrates its instances.

AI-assisted (Cursor). Not yet reviewed by a human.
@Carreau
Carreau force-pushed the fix/14984-autoreload-partial branch from f31b593 to be9b09b Compare October 21, 2026 12:14

This branch has not been deployed

No deployments
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.

autoreload breaks on partial

1 participant