[issue43481] PyEval_EvalCode() namespace issue not observed in Python 2.7.

2021-03-24 Thread Terry J. Reedy
Terry J. Reedy added the comment: Perhaps both. If you want more discussion, please post to python-list. -- ___ Python tracker ___ ___

[issue43481] PyEval_EvalCode() namespace issue not observed in Python 2.7.

2021-03-24 Thread Chris Morton
Chris Morton added the comment: Is this change in behavior considered to be by design or is this issue an unintended consequence? It seems inconsistent that comprehensions have no visibility of variable previously defined in the same scoping for this particular use-case. Is there a way to wo

[issue43481] PyEval_EvalCode() namespace issue not observed in Python 2.7.

2021-03-20 Thread Terry J. Reedy
Terry J. Reedy added the comment: Foolish me. Commenting out the first exec results in the 2nd exec raising. Commenting out the 2nd exec also results in the class code raising, which is what I expected. The point of the class code is to partially explain the exception, which is not a bug,

[issue43481] PyEval_EvalCode() namespace issue not observed in Python 2.7.

2021-03-20 Thread Chris Morton
Chris Morton added the comment: Hi Terry, The reason why your code does not reproduce the issue is because you first execute the code in a global context which then puts the definition of c in that context. Subsequent calling in the local context then works. If you remove the first exec call

[issue43481] PyEval_EvalCode() namespace issue not observed in Python 2.7.

2021-03-19 Thread Terry J. Reedy
Terry J. Reedy added the comment: I cannot reproduce in Python with either 3.8 or 3.10. (Please try with latter if you can.) I thought the issue might possibly be passing two different dicts, which results in the code being executed as if in a class statement, but it is not. code = '''

[issue43481] PyEval_EvalCode() namespace issue not observed in Python 2.7.

2021-03-16 Thread Chris Morton
Chris Morton added the comment: Root cause appears to be indexing c with [] operator. Replacing len(c) with 4 produces the same error. -- ___ Python tracker ___ _

[issue43481] PyEval_EvalCode() namespace issue not observed in Python 2.7.

2021-03-12 Thread Chris Morton
New submission from Chris Morton : Compiling (Window 10, MSVS 16): #include int main(int argc, char* argv[]) { const char* code = "c=[1,2,3,4]\nd={'list': [c[i] for i in range(len(c))]}\nprint(d)\n"; Py_Initialize(); PyObject* pycode = Py_CompileString(code, "", Py_file_input )