Skip to content

Commit

Permalink
Fix incorrect usage of exec
Browse files Browse the repository at this point in the history
As of PEP558, `locals()` is not populated by `exec()`. This change means
that this call is broken on Python 3.13.
  • Loading branch information
QuLogic committed Aug 26, 2024
1 parent 50fe6db commit c02bd21
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions gramps/gen/display/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def _gen_cooked_func(self, format_str):
The new function is of the form::
def fn(first, raw_surname_list, suffix, title, call,):
def fn(first, raw_surname_list, suffix, title, call, nick, famnick):
return "%s %s" % (first,suffix)
Specific symbols for parts of a name are defined (keywords given):
Expand Down Expand Up @@ -1179,8 +1179,7 @@ def name_grouping_data(self, db, pn):

def _make_fn(self, format_str, d, args):
"""
Create the name display function and handles dependent
punctuation.
Create the name display function and handles dependent punctuation.
"""
# d is a dict: dict[code] = (expr, word, translated word)

Expand Down Expand Up @@ -1288,18 +1287,17 @@ def ifNotEmpty(str,p,s):
",".join(param),
)
try:
exec(s) in globals(), locals()
return locals()["fn"]
except:
result = {}
exec(s, globals(), result)
return result["fn"]
except SyntaxError:
LOG.error(
"\n"
+ "Wrong name format string %s" % new_fmt
+ "\n"
+ ("ERROR, Edit Name format in Preferences->Display to correct")
+ "\n"
+ _("Wrong name format string %s") % new_fmt
+ "\n"
+ ("ERROR, Edit Name format in Preferences->Display to correct")
"Wrong name format string %s\n"
"ERROR, Edit Name format in Preferences->Display to correct\n"
+ _("Wrong name format string %s")
+ "\nERROR, Edit Name format in Preferences->Display to correct",
new_fmt,
new_fmt,
)

def errfn(*arg):
Expand Down

0 comments on commit c02bd21

Please sign in to comment.