@@ -1553,27 +1553,32 @@ public abstract static class PrintNode extends PythonBuiltinNode {
1553
1553
@ Specialization
1554
1554
@ SuppressWarnings ("unused" )
1555
1555
PNone printNoKeywords (VirtualFrame frame , Object [] values , PNone sep , PNone end , PNone file , PNone flush ,
1556
- @ Shared ("callWrite" ) @ Cached PyObjectCallMethodObjArgs callWrite ,
1556
+ @ Shared ("lookupWrite" ) @ Cached PyObjectLookupAttr lookupWrite ,
1557
+ @ Shared ("callWrite" ) @ Cached CallNode callWrite ,
1557
1558
@ Shared ("callFlush" ) @ Cached PyObjectCallMethodObjArgs callFlush ,
1558
1559
@ Shared ("strNode" ) @ Cached PyObjectStrAsObjectNode strNode ) {
1559
1560
Object stdout = getStdout ();
1560
- return printAllGiven (frame , values , DEFAULT_SEPARATOR , DEFAULT_END , stdout , false , callWrite , callFlush , strNode );
1561
+ return printAllGiven (frame , values , DEFAULT_SEPARATOR , DEFAULT_END , stdout , false , lookupWrite , callWrite , callFlush , strNode );
1561
1562
}
1562
1563
1563
1564
@ Specialization (guards = {"!isNone(file)" , "!isNoValue(file)" })
1564
1565
PNone printAllGiven (VirtualFrame frame , Object [] values , String sep , String end , Object file , boolean flush ,
1565
- @ Shared ("callWrite" ) @ Cached PyObjectCallMethodObjArgs callWrite ,
1566
+ @ Shared ("lookupWrite" ) @ Cached PyObjectLookupAttr lookupWrite ,
1567
+ @ Shared ("callWrite" ) @ Cached CallNode callWrite ,
1566
1568
@ Shared ("callFlush" ) @ Cached PyObjectCallMethodObjArgs callFlush ,
1567
1569
@ Shared ("strNode" ) @ Cached PyObjectStrAsObjectNode strNode ) {
1568
1570
int lastValue = values .length - 1 ;
1571
+ // Note: the separate lookup is necessary due to different __getattr__ treatment than
1572
+ // method lookup
1573
+ Object writeMethod = lookupWrite .executeStrict (frame , this , file , "write" );
1569
1574
for (int i = 0 ; i < lastValue ; i ++) {
1570
- callWrite .execute (frame , file , "write" , strNode .execute (frame , values [i ]));
1571
- callWrite .execute (frame , file , "write" , sep );
1575
+ callWrite .execute (frame , writeMethod , strNode .execute (frame , values [i ]));
1576
+ callWrite .execute (frame , writeMethod , sep );
1572
1577
}
1573
1578
if (lastValue >= 0 ) {
1574
- callWrite .execute (frame , file , "write" , strNode .execute (frame , values [lastValue ]));
1579
+ callWrite .execute (frame , writeMethod , strNode .execute (frame , values [lastValue ]));
1575
1580
}
1576
- callWrite .execute (frame , file , "write" , end );
1581
+ callWrite .execute (frame , writeMethod , end );
1577
1582
if (flush ) {
1578
1583
callFlush .execute (frame , file , "flush" );
1579
1584
}
@@ -1586,7 +1591,8 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
1586
1591
@ Cached CastToJavaStringNode castEnd ,
1587
1592
@ Cached ("createIfTrueNode()" ) CoerceToBooleanNode castFlush ,
1588
1593
@ Cached PRaiseNode raiseNode ,
1589
- @ Shared ("callWrite" ) @ Cached PyObjectCallMethodObjArgs callWrite ,
1594
+ @ Shared ("lookupWrite" ) @ Cached PyObjectLookupAttr lookupWrite ,
1595
+ @ Shared ("callWrite" ) @ Cached CallNode callWrite ,
1590
1596
@ Shared ("callFlush" ) @ Cached PyObjectCallMethodObjArgs callFlush ,
1591
1597
@ Shared ("strNode" ) @ Cached PyObjectStrAsObjectNode strNode ) {
1592
1598
String sep ;
@@ -1615,7 +1621,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
1615
1621
} else {
1616
1622
flush = castFlush .executeBoolean (frame , flushIn );
1617
1623
}
1618
- return printAllGiven (frame , values , sep , end , file , flush , callWrite , callFlush , strNode );
1624
+ return printAllGiven (frame , values , sep , end , file , flush , lookupWrite , callWrite , callFlush , strNode );
1619
1625
}
1620
1626
1621
1627
private Object getStdout () {
0 commit comments