Skip to content

deepreload: don't reload standard-library modules (fixes #14292, closes #13331) - #15402

Open
glaziermag wants to merge 1 commit into
ipython:mainfrom
glaziermag:fix/deepreload-stdlib
Open

glaziermag wants to merge 1 commit into
ipython:mainfrom
glaziermag:fix/deepreload-stdlib

Conversation

@glaziermag

Copy link
Copy Markdown

🤖🤖 Agent-written change (Claude Code), per CONTRIBUTING.md.

dreload(m) re-executes every module imported while its import hook is active, standard library included. Reloading os rebinds os.environ to an instance of a new os._Environ class, so IPython's own environ{...} printer, registered on the import-time type (pretty.py:853), stops matching. That is #14292. Reloading enum, re and the like duplicates their classes the same way.

This PR skips any module whose top-level name is in sys.stdlib_module_names, as #13331 suggested. Closes #13331, fixes #14292.

import os, sys, tempfile, pathlib
from IPython.lib.deepreload import reload as dreload
from IPython.lib.pretty import pretty

d = tempfile.mkdtemp(); sys.path.insert(0, d)
pathlib.Path(d, "m.py").write_text("import os\n")
import m
dreload(m)                       # main: prints "Reloading os", "Reloading abc", ...
print(pretty(os.environ)[:9])    # main: environ({    this branch: environ{'

The new test_deepreload_skips_stdlib covers os, enum and a stdlib submodule (json.decoder).

Related: the Linux/3.11 skips added in 8ec6f87 blame "an upstream matplotlib marker-style regression" and "an os.environ repr format difference". They match this mechanism. The 07-07 job failed test_pretty_environ with environ({...}) plus Unrecognized marker style 'None'. With the skips removed, a fork run in which a stdlib reload happens earlier in the session (the new test, run against main's deepreload.py) fails exactly those six tests with the same messages, plus the new test. On today's main they pass on Linux/3.11 with the skips removed (run, variant main), so the skips could be dropped. I can add that to this PR if you'd like.

🤖 Generated with Claude Code

dreload() re-executed any stdlib module imported while its import hook
was active (os, enum, re, codecs, ...), replacing os.environ with an
instance of a new os._Environ class and enum.Enum with a new class.

Closes ipython#13331, fixes ipython#14292.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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.

test_deepreload breaks test_pretty_environ with Python 3.12 Maybe use sys.stdlib_module_names for deepreload.

1 participant