@@ -1689,23 +1689,13 @@ static Object doHook(VirtualFrame frame, PythonModule sys, Object obj,
1689
1689
throw raiseNode .get (inliningTarget ).raise (RuntimeError , LOST_S , "sys.stdout" );
1690
1690
}
1691
1691
1692
- boolean reprWriteOk = false ;
1693
- boolean unicodeEncodeError = false ;
1692
+ Object reprVal = null ;
1694
1693
try {
1695
- Object reprVal = objectRepr (frame , inliningTarget , obj , reprAsObjectNode );
1696
- if (reprVal == null ) {
1697
- reprWriteOk = false ;
1698
- } else {
1699
- reprWriteOk = true ;
1700
- fileWriteString (frame , inliningTarget , stdOut , castToStringNode .execute (inliningTarget , reprVal ), getAttr , callNode );
1701
- }
1694
+ reprVal = objectRepr (frame , inliningTarget , obj , reprAsObjectNode );
1702
1695
} catch (PException pe ) {
1703
1696
pe .expect (inliningTarget , UnicodeEncodeError , unicodeEncodeErrorProfile );
1704
1697
// repr(o) is not encodable to sys.stdout.encoding with sys.stdout.errors error
1705
1698
// handler (which is probably 'strict')
1706
- unicodeEncodeError = true ;
1707
- }
1708
- if (!reprWriteOk && unicodeEncodeError ) {
1709
1699
// inlined sysDisplayHookUnencodable
1710
1700
final TruffleString stdoutEncoding = objectLookupAttrAsString (frame , inliningTarget , stdOut , T_ENCODING , lookupAttr , castToStringNode );
1711
1701
final Object reprStr = objectRepr (frame , inliningTarget , obj , reprAsObjectNode );
@@ -1720,6 +1710,9 @@ static Object doHook(VirtualFrame frame, PythonModule sys, Object obj,
1720
1710
fileWriteString (frame , inliningTarget , stdOut , castToStringNode .execute (inliningTarget , str ), getAttr , callNode );
1721
1711
}
1722
1712
}
1713
+ if (reprVal != null ) {
1714
+ fileWriteString (frame , inliningTarget , stdOut , castToStringNode .execute (inliningTarget , reprVal ), getAttr , callNode );
1715
+ }
1723
1716
1724
1717
fileWriteString (frame , inliningTarget , stdOut , T_NEWLINE , getAttr , callNode );
1725
1718
setAttr .execute (frame , inliningTarget , builtins , T___ , obj );
0 commit comments