PyPy3 on windows does not print with '\r'

Create issue
Issue #3007 resolved
Görre Mörre created an issue

Noticed that PyPy3 is missing the '\r' when using print(). Tested to be missing on PyPy3 6.0.0. and PyPy3 7.1.1-beta0. I'm running windows 10.

PyPy2, CPython 2 and CPython 3 all prints with '\r'.

Comments (12)

  1. Armin Rigo

    This works for me like I would expect it to (tested with pypy3.5 6.0.0 and pypy3.6 7.1.1):

    >>>> f=open('x.txt', 'w')
    >>>> print('hello', file=f)
    >>>> f.close()
    >>>> open('x.txt', 'rb').read()

    Can you provide us with an example? Thanks!

  2. Armin Rigo

    How can you tell if something was printed to the Windows console with or without '\r'? Or are you using a different console than the standard one? In general, I would expect print() to add a '\r' or not depending on whether it writes to a file opened in binary or in text mode, so maybe the problem here is really that stdout is opened in binary mode for you. For me, running the standard Windows console, it is opened in text mode.

  3. Görre Mörre reporter

    Sorry if I have been unclear. Let be


    what I'm doing is just running it and saving the output

    pypy3 > out

    out should now contain only '\n' and not '\r\n'. This happens no matter how I run it. I've tried using cmd on windows, I've also tried using git bash for windows. Everyone I've spoke to about this has had the same problem. Also I've only seen this with PyPy3. PyPy2, CPython 2 and CPython 3 all prints with '\r'.

  4. Armin Rigo

    I think the exact behavior of CPython (and PyPy2) is to enable the "universal newline" mode in all three files instead of just stdin. Additionally, I think that when we run python with the -u option, the "universal newline" translations should be disabled. I've implemented it in db5a7e05dcd9. Does it sound correct to you?

  5. Görre Mörre reporter

    “Additionally, I think that when we run python with the -u option, the "universal newline" translations should be disabled.“

    I’m not too sure about these things, but just running

    import sys

    in CPython3 with -u makes it output \r\n (tested on CPython 3.7.3). But CPython2 with -u outputs \n (so CPython2 disables universal newlines with -u). Seems like CPython2 and CPython3 does things differently for some reason.

  6. Armin Rigo

    OK, so sys.stdout('\n') always writes \r\n. This seems to be independent on the -u option. Implementation attempt in a3e2d215641c.

    os.write(1, b'\n') always writes only \n, which I think is the current behavior already.

  7. Görre Mörre reporter

    Yeah think that sounds correct. I think that in python 3 they want all \n output with str to be converted to \r\n, but for byte strings that should not happen. So for example sys.stdout.buffer.write(b'\n') should not convert, and neither should os.write(1, b'\n').

  8. Log in to comment