[issue42190] global declarations affect too much inside exec or compile

2020-10-30 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: > Maybe someone can bisect and find when this started happening? As far as I understand, this has been the case since Python 2 at least: $cat code.py gdict = {} ldict = {} exec(''' x = 1 def f(): global x''', gdict, ldict) print(('x' in gdict, 'x' in

[issue42190] global declarations affect too much inside exec or compile

2020-10-30 Thread Guido van Rossum
Guido van Rossum added the comment: Looks like a bug. Maybe someone can bisect and find when this started happening? -- ___ Python tracker ___

[issue42190] global declarations affect too much inside exec or compile

2020-10-30 Thread Terry J. Reedy
Terry J. Reedy added the comment: exec with different global and local dicts is most like executing code in a class definition, where locals is different from globals. But mimicking your exec with an actual class statement does not produce the same result. >>> gdict = {} >>> class C:

[issue42190] global declarations affect too much inside exec or compile

2020-10-28 Thread Kevin Shweh
New submission from Kevin Shweh : A global declaration inside a function is only supposed to affect assignments inside that function, but in code executed with exec, a global declaration affects assignments outside the function: >>> gdict = {} >>> ldict = {} >>> exec('x = 1', gdict, ldict)