Skip to content

Commit

Permalink
sagemathgh-39185: Fix find_replacements with Python 3.13
Browse files Browse the repository at this point in the history
    
After PEP 667 implementation [1] `globals()` changes within an `exec`
call are not propagated outside the call

[1] python/cpython@b034f14a4b6e9197d3926046721
b8b4b4b4f5b3d
    
URL: sagemath#39185
Reported by: Antonio Rojas
Reviewer(s): user202729
  • Loading branch information
Release Manager committed Jan 8, 2025
2 parents 02b81c7 + cee808a commit c8b4dac
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/sage/misc/replace_dot_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ def find_replacements(location, package_regex=None, verbose=False):
to_exec = to_exec.replace("'", '').replace('"', '')
if (to_exec[-1] == ','):
to_exec = to_exec[:-1]
exec(to_exec)
glob = dict()
exec(to_exec, glob)
except ModuleNotFoundError as err:
print(f'ModuleNotFoundError: {err} found when trying to execute {to_exec}')
except ImportError as err:
print(f'ImportError: {err} found when trying to execute {to_exec}')

try: # try to evaluate the list of module names to get a list of the modules themselves which we can call import_statements on
modules = eval(to_eval)
modules = eval(to_eval, glob)
except NameError as err:
print(f'NameError: {err} found when trying to evaluate {to_eval} at {location}:{row_index + 1}')
except SyntaxError as err:
Expand Down

0 comments on commit c8b4dac

Please sign in to comment.