@@ -1045,29 +1045,32 @@ static final class SyntaxErrData {
10451045 final int lineNo ;
10461046 final int offset ;
10471047 final Object text ;
1048+ final boolean err ;
10481049
1049- SyntaxErrData (Object message , Object fileName , int lineNo , int offset , Object text ) {
1050+ SyntaxErrData (Object message , Object fileName , int lineNo , int offset , Object text , boolean err ) {
10501051 this .message = message ;
10511052 this .fileName = fileName ;
10521053 this .lineNo = lineNo ;
10531054 this .offset = offset ;
10541055 this .text = text ;
1056+ this .err = err ;
10551057 }
10561058 }
10571059
10581060 private SyntaxErrData parseSyntaxError (VirtualFrame frame , Object err ) {
1059- String msg , fileName = null , text = null ;
1060- int lineNo = 0 , offset = 0 , hold = 0 ;
1061+ Object v , msg ;
1062+ String fileName = null , text = null ;
1063+ int lineNo = 0 , offset = 0 , hold ;
10611064
10621065 // new style errors. `err' is an instance
1063- msg = objectLookupAttrAsString (frame , err , ATTR_MSG );
1064- if (msg == null ) {
1065- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1066+ msg = objectLookupAttr (frame , err , ATTR_MSG );
1067+ if (msg == PNone . NO_VALUE ) {
1068+ return new SyntaxErrData (null , fileName , lineNo , offset , text , true );
10661069 }
10671070
1068- Object v = objectLookupAttr (frame , err , ATTR_FILENAME );
1071+ v = objectLookupAttr (frame , err , ATTR_FILENAME );
10691072 if (v == PNone .NO_VALUE ) {
1070- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1073+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
10711074 }
10721075 if (v == PNone .NONE ) {
10731076 fileName = VALUE_STRING ;
@@ -1077,42 +1080,42 @@ private SyntaxErrData parseSyntaxError(VirtualFrame frame, Object err) {
10771080
10781081 v = objectLookupAttr (frame , err , ATTR_LINENO );
10791082 if (v == PNone .NO_VALUE ) {
1080- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1083+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
10811084 }
10821085 try {
10831086 hold = longAsInt (frame , v );
10841087 } catch (PException pe ) {
1085- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1088+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
10861089 }
10871090
10881091 lineNo = hold ;
10891092
10901093 v = objectLookupAttr (frame , err , ATTR_OFFSET );
10911094 if (v == PNone .NO_VALUE ) {
1092- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1095+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
10931096 }
10941097 if (v == PNone .NONE ) {
10951098 offset = -1 ;
10961099 } else {
10971100 try {
10981101 hold = longAsInt (frame , v );
10991102 } catch (PException pe ) {
1100- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1103+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
11011104 }
11021105 offset = hold ;
11031106 }
11041107
11051108 v = objectLookupAttr (frame , err , ATTR_TEXT );
11061109 if (v == PNone .NO_VALUE ) {
1107- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1110+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , true );
11081111 }
11091112 if (v == PNone .NONE ) {
11101113 text = null ;
11111114 } else {
11121115 text = castToString (v );
11131116 }
11141117
1115- return new SyntaxErrData (msg , fileName , lineNo , offset , text );
1118+ return new SyntaxErrData (msg , fileName , lineNo , offset , text , false );
11161119 }
11171120
11181121 private void printErrorText (VirtualFrame frame , Object out , SyntaxErrData syntaxErrData ) {
@@ -1200,14 +1203,16 @@ protected void printException(VirtualFrame frame, PythonModule sys, Object out,
12001203 if (objectHasAttr (frame , value , ATTR_PRINT_FILE_AND_LINE )) {
12011204 // SyntaxError case
12021205 final SyntaxErrData syntaxErrData = parseSyntaxError (frame , value );
1203- value = syntaxErrData .message ;
1204- StringBuilder sb = PythonUtils .newStringBuilder (" File \" " );
1205- PythonUtils .append (sb , castToString (objectStr (frame , syntaxErrData .fileName )), "\" , line " , syntaxErrData .lineNo , "\n " );
1206- fileWriteString (frame , out , PythonUtils .sbToString (sb ));
1207-
1208- // Can't be bothered to check all those PyFile_WriteString() calls
1209- if (syntaxErrData .text != null ) {
1210- printErrorText (frame , out , syntaxErrData );
1206+ if (!syntaxErrData .err ) {
1207+ value = syntaxErrData .message ;
1208+ StringBuilder sb = PythonUtils .newStringBuilder (" File \" " );
1209+ PythonUtils .append (sb , castToString (objectStr (frame , syntaxErrData .fileName )), "\" , line " , syntaxErrData .lineNo , "\n " );
1210+ fileWriteString (frame , out , PythonUtils .sbToString (sb ));
1211+
1212+ // Can't be bothered to check all those PyFile_WriteString() calls
1213+ if (syntaxErrData .text != null ) {
1214+ printErrorText (frame , out , syntaxErrData );
1215+ }
12111216 }
12121217 }
12131218
0 commit comments