@@ -613,10 +613,14 @@ protected void assertNoFreeVars(PCode code) {
613
613
Object [] freeVars = code .getFreeVars ();
614
614
if (freeVars .length > 0 ) {
615
615
hasFreeVarsBranch .enter ();
616
- throw raise (PythonBuiltinClassType .TypeError , "code object passed to eval/exec may not contain free variables" );
616
+ throw raise (PythonBuiltinClassType .TypeError , "code object passed to %s may not contain free variables" , getMode () );
617
617
}
618
618
}
619
619
620
+ protected String getMode () {
621
+ return "eval" ;
622
+ }
623
+
620
624
protected boolean isMapping (Object object ) {
621
625
// tfel: it seems that CPython only checks that there is __getitem__
622
626
if (object instanceof PDict ) {
@@ -631,7 +635,7 @@ protected boolean isAnyNone(Object object) {
631
635
}
632
636
633
637
protected PCode createAndCheckCode (Object source ) {
634
- PCode code = compileNode .execute (source , "<string>" , "eval" , 0 , false , -1 );
638
+ PCode code = compileNode .execute (source , "<string>" , getMode () , 0 , false , -1 );
635
639
assertNoFreeVars (code );
636
640
return code ;
637
641
}
@@ -736,6 +740,11 @@ PNone badLocals(@SuppressWarnings("unused") Object source, @SuppressWarnings("un
736
740
abstract static class ExecNode extends EvalNode {
737
741
protected abstract Object executeInternal (VirtualFrame frame );
738
742
743
+ @ Override
744
+ protected String getMode () {
745
+ return "exec" ;
746
+ }
747
+
739
748
@ Override
740
749
public final Object execute (VirtualFrame frame ) {
741
750
executeInternal (frame );
0 commit comments