From e0de2bd7ba7517dce939bab0889a6762101efa46 Mon Sep 17 00:00:00 2001 From: Sungmin-Joo Date: Wed, 25 Sep 2019 11:08:24 +0900 Subject: [PATCH 1/4] Fix "end" option Fix line 190 to 193. The print function corrected the end option not applied. Added code performed when "end" value of parameter "kwargs" is not "nil". --- builtin/builtin.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/builtin/builtin.go b/builtin/builtin.go index bb4158c4..81ecc9dc 100644 --- a/builtin/builtin.go +++ b/builtin/builtin.go @@ -176,10 +176,10 @@ flush: whether to forcibly flush the stream.` func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Object, error) { var ( - sepObj py.Object = py.String(" ") + sepObj py.Object = py.String(" ") endObj py.Object = py.String("\n") file py.Object = py.MustGetModule("sys").Globals["stdout"] - flush py.Object + flush py.Object ) kwlist := []string{"sep", "end", "file", "flush"} err := py.ParseTupleAndKeywords(nil, kwargs, "|ssOO:print", kwlist, &sepObj, &endObj, &file, &flush) @@ -187,6 +187,10 @@ func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Obje return nil, err } sep := sepObj.(py.String) + + if kwargs["end"] != nil { + endObj = kwargs["end"] + } end := endObj.(py.String) write, err := py.GetAttrString(file, "write") @@ -195,7 +199,7 @@ func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Obje } for i, v := range args { - v, err := py.Str(v) + v, err := py.Str(v) if err != nil { return nil, err } @@ -209,7 +213,7 @@ func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Obje _, err = py.Call(write, py.Tuple{sep}, nil) if err != nil { return nil, err - } + } } } From 40d09788c218c8b92f0d982f6725b3f1d2941206 Mon Sep 17 00:00:00 2001 From: Sungmin-Joo Date: Thu, 26 Sep 2019 10:28:22 +0900 Subject: [PATCH 2/4] Fix "end" option Fix line 190 to 193. The print function corrected the end option not applied. Added code performed when "end" value of parameter "kwargs" is not "nil". --- builtin/builtin.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/builtin.go b/builtin/builtin.go index 81ecc9dc..2512e2fd 100644 --- a/builtin/builtin.go +++ b/builtin/builtin.go @@ -176,10 +176,10 @@ flush: whether to forcibly flush the stream.` func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Object, error) { var ( - sepObj py.Object = py.String(" ") + sepObj py.Object = py.String(" ") endObj py.Object = py.String("\n") file py.Object = py.MustGetModule("sys").Globals["stdout"] - flush py.Object + flush py.Object ) kwlist := []string{"sep", "end", "file", "flush"} err := py.ParseTupleAndKeywords(nil, kwargs, "|ssOO:print", kwlist, &sepObj, &endObj, &file, &flush) @@ -199,7 +199,7 @@ func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Obje } for i, v := range args { - v, err := py.Str(v) + v, err := py.Str(v) if err != nil { return nil, err } @@ -213,7 +213,7 @@ func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Obje _, err = py.Call(write, py.Tuple{sep}, nil) if err != nil { return nil, err - } + } } } From 5e9266f12387d5230644b5d1012c7abab8303c70 Mon Sep 17 00:00:00 2001 From: Sungmin-Joo Date: Thu, 26 Sep 2019 10:34:32 +0900 Subject: [PATCH 3/4] add "end" option test add "end" option test in line 312 --- builtin/tests/builtin.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/builtin/tests/builtin.py b/builtin/tests/builtin.py index 88cc38c2..0410b94b 100644 --- a/builtin/tests/builtin.py +++ b/builtin/tests/builtin.py @@ -309,6 +309,12 @@ def gen2(): with open("testfile", "r") as f: assert f.read() == "1,2,3,\n" +with open("testfile", "w") as f: + print("hello",end="123", file=f) + +with open("testfile", "r") as f: + assert f.read() == "hello123" + doc="round" assert round(1.1) == 1.0 From 5425d9c3701b554340bf3591bb312f536fc3c4ba Mon Sep 17 00:00:00 2001 From: Sungmin-Joo Date: Thu, 26 Sep 2019 11:03:41 +0900 Subject: [PATCH 4/4] add "end" option test add "end" option test add "end" option test in line 312 --- builtin/tests/builtin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/tests/builtin.py b/builtin/tests/builtin.py index 0410b94b..e3a1c5a5 100644 --- a/builtin/tests/builtin.py +++ b/builtin/tests/builtin.py @@ -310,7 +310,7 @@ def gen2(): assert f.read() == "1,2,3,\n" with open("testfile", "w") as f: - print("hello",end="123", file=f) + print("hello",sep="",end="123", file=f) with open("testfile", "r") as f: assert f.read() == "hello123"