ARTICLE AD BOX
I'm encountering a peculiar issue when using Python's exec function within scripts that are run across different Git worktrees. Specifically, I've observed that the behavior of exec (and by extension, eval) seems to be subtly affected by the active Git worktree, leading to inconsistent module resolution and potentially corrupted internal state for modules loaded via exec.
Consider this:
A Python script uses exec(code_string). code_string contains an import statement or references a module that has been dynamically loaded or modified. This script is executed in an environment where the current working directory has changed due to Git's worktree mechanism (e.g., using git worktree add).It appears that Python's internal module cache, or perhaps the way it resolves paths for imported modules, might be conflating information from different worktrees if the underlying .git directory is the same. This can lead to exec picking up stale or incorrect versions of modules.
Are there specific environment variables or Python configurations that exacerbate or mitigate this issue?
