-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
importlib.reload not updated when only change a little bit code layout #120932
Comments
This is confirmed on Python 3.12 and the CPython main branch. Here's a smaller reproducer: import importlib
from pathlib import Path
MODULE_NAME = "tmod"
MODULE_PATH = Path(MODULE_NAME + ".py")
with open(MODULE_PATH, "w") as f:
f.write("a = 1")
mod = importlib.import_module(MODULE_NAME)
old = mod.a
with open(MODULE_PATH, "w") as f:
f.write("a = 2")
mod = importlib.reload(mod)
new = mod.a
assert old != new # failed, 1 != 1 At first glance, this looks like a problem related to cache invalidation inside I played around with this a little bit, and it seems likely that the problem is with I'll submit a patch for this ASAP. |
The problem is here. The repro updates the file too quickly for the number to be different, and when the size is the same, it doesn't get caught there either. I'm not all too sure this is worth fixing, considering it will probably have negative performance benefits, and only happens in very extreme cases. It might be worth documenting, though. What do you think, @serhiy-storchaka (pinging you considering you helped on the previous |
This is not related to |
Repeating myself from #121376 (comment):
This is possible, but this may be not so simple. Currently the code compares the timestamp of the
|
#121620 implements this idea. |
Right, I was just assuming you had knowledge of the import system :) |
Bug report
Bug description:
When I added a small number of comments, the results changed
CPython versions tested on:
3.8
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: