@@ -16,7 +16,6 @@ package grumpy
1616
1717import (
1818 "fmt"
19- "io"
2019 "log"
2120 "os"
2221 "reflect"
@@ -641,7 +640,7 @@ func Print(f *Frame, args Args, nl bool) *BaseException {
641640 } else if len (args ) > 0 {
642641 end = " "
643642 }
644- return pyPrint (f , args , " " , end , os . Stdout )
643+ return pyPrint (f , args , " " , end , Stdout )
645644}
646645
647646// Repr returns a string containing a printable representation of o. This is
@@ -1216,17 +1215,30 @@ func hashNotImplemented(f *Frame, o *Object) (*Object, *BaseException) {
12161215}
12171216
12181217// pyPrint encapsulates the logic of the Python print function.
1219- func pyPrint (f * Frame , args Args , sep , end string , file io. Writer ) * BaseException {
1218+ func pyPrint (f * Frame , args Args , sep , end string , file * File ) * BaseException {
12201219 for i , arg := range args {
12211220 if i > 0 {
1222- fmt .Fprint (file , sep )
1221+ err := file .writeString (sep )
1222+ if err != nil {
1223+ return f .RaiseType (IOErrorType , err .Error ())
1224+ }
12231225 }
1226+
12241227 s , raised := ToStr (f , arg )
12251228 if raised != nil {
12261229 return raised
12271230 }
1228- fmt .Fprint (file , s .Value ())
1231+
1232+ err := file .writeString (s .Value ())
1233+ if err != nil {
1234+ return f .RaiseType (IOErrorType , err .Error ())
1235+ }
12291236 }
1230- fmt .Fprint (file , end )
1237+
1238+ err := file .writeString (end )
1239+ if err != nil {
1240+ return f .RaiseType (IOErrorType , err .Error ())
1241+ }
1242+
12311243 return nil
12321244}
0 commit comments