Skip to content

Fixed "print function's "end" option error in CPython" #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Fixed "print function's "end" option error in CPython" #92

wants to merge 2 commits into from

Conversation

Sungmin-Joo
Copy link
Contributor

@Sungmin-Joo Sungmin-Joo commented Sep 27, 2019

The following code writes different string to the stream than in CPython:

print(1,2,3, end="||\n")

I fixed that bug by modifying the code
resolved: #93

The following code writes different string to the stream than in CPython:
print(1,2,3, end="||\n")

The following code writes different string to the stream than in CPython:
print(1,2,3, end="||\n")

I fixed that bug by modifying the code
@codecov-io
Copy link

codecov-io commented Sep 27, 2019

Codecov Report

Merging #92 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #92      +/-   ##
=========================================
+ Coverage   69.09%   69.1%   +0.01%     
=========================================
  Files          60      60              
  Lines       10674   10678       +4     
=========================================
+ Hits         7375    7379       +4     
  Misses       2781    2781              
  Partials      518     518
Impacted Files Coverage Δ
builtin/builtin.go 79.89% <100%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e427daf...0d6c264. Read the comment docs.

@Sungmin-Joo Sungmin-Joo changed the title Fix "end" option in print function Fixed "print function's "end" option error in CPython" Sep 27, 2019
Copy link
Collaborator

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sungmin-Joo Please add a unit test which you updated.

@corona10 corona10 requested a review from ncw September 27, 2019 06:00
add "end" test in cpython
@Sungmin-Joo
Copy link
Contributor Author

@corona10
Is it a proper test?
If not, I will try again tomorrow.

@corona10
Copy link
Collaborator

@Sungmin-Joo
You should show the test

AS-IS

>>> print(1,2,3, end="||\n")
1||
2||
3||

TO-BE

>>> print(1,2,3, end="||\n")
1 2 3||

Copy link
Collaborator

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is not proper.

@@ -186,6 +186,12 @@ func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Obje
if err != nil {
return nil, err
}

if kwargs["sep"] != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about:

switch sep, ok := kwargs["sep"]; ok {
case true:
    sepObj = sep
default:
    sepObj = py.String(" ")
}

print("hello","gpython", end="123\n")
except TypeError as e:
ok = True
assert ok, "TypeError not raised"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert ok, "TypeError not raised"
assert ok, "TypeError not raised when 'sep' is not in the kwargs dict"

that said, I am not sure I understand this test.
do we really want this line to raise an exception? why?

@@ -281,6 +281,12 @@ def gen2():
ok = True
assert ok, "TypeError not raised"

try:
print("hello","gpython", end="123\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print("hello","gpython", end="123\n")
print("hello", "gpython", end="123\n")

@corona10
Copy link
Collaborator

@Sungmin-Joo @sbinet
Sorry,
I think that we should fix #90 was not the proper approach.

err := py.ParseTupleAndKeywords(nil, kwargs, "|ssOO:print", kwlist, &sepObj, &endObj, &file, &flush)

I am now closing this PR
Let's fix this issue with proper approach :)

@corona10 corona10 closed this Sep 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

print function's "end" option error in CPython
4 participants