This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: TextCalendar.prweek/month/year outputs an extra whitespace character
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: belopolsky, python-dev, serhiy.storchaka, xiang.zhang
Priority: normal Keywords: patch

Created on 2016-09-23 08:51 by xiang.zhang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
calendar_whitespace.patch xiang.zhang, 2016-09-23 08:51 review
calendar_whitespace_v2.patch xiang.zhang, 2016-09-23 09:54 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (9)
msg277256 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-09-23 08:51
Currently TextCalendar.prweek/month/year outputs an extra whitespace which makes the output weird:

>>> calendar.TextCalendar().prweek([(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7)], 2)
 1  2  3  4  5  6  7 >>> calendar.TextCalendar().prmonth(2016,9)
   September 2016
Mo Tu We Th Fr Sa Su
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
 >>>
msg277258 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-23 09:02
The patch LGTM. Could you please add tests?

I suppose this is a consequence of porting from Python 2 to Python 3 (maybe with 2to3). Usually "print x," in Python 2 corresponds to "print(x, end=' ')" in Python 3. But if x ends with \n, print with a comma in Python 2 don't add a space, this corresponds to "print(x, end='')". Similar issue was fixed not long ago. Maybe there are other similar issues in the stdlib or scripts.
msg277260 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-23 09:15
prweek() in Python 2 adds a final space. Python 3 version looks correct.
msg277269 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-09-23 11:07
A single `print x,` seems to me won't add the trailing space. And I don't understand why in py2 repl even with comma there is still a newline:

>>> print 'a',
a
>>> 

>>> print('a', end='')
a>>>
msg277451 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-26 19:09
Actually the behavior of the print statement in Python 2 is more complex.

"print x," doesn't output a space after x, but sets the softspace attribute of the file to true (unless x is a string ending with non-space whitespace character like \n or \t). print tests this flag before outputting a value and outputs a space if it is true. Any output to a file resets this flag. This behavior can't be exactly reproduced in Python 3.
msg278070 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-04 17:52
It looks to me that only prmonth() should be changed. prweek() and pryear() either match the behavior of PYthon 2 or are the good approximation of it.
msg279396 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-10-25 12:04
New changeset 8d54c2a1c796 by Serhiy Storchaka in branch '3.5':
Issue #28255: calendar.TextCalendar().prmonth() no longer prints a space
https://hg.python.org/cpython/rev/8d54c2a1c796

New changeset ebe5bd33f86f by Serhiy Storchaka in branch '3.6':
Issue #28255: calendar.TextCalendar().prmonth() no longer prints a space
https://hg.python.org/cpython/rev/ebe5bd33f86f

New changeset 049e58f74272 by Serhiy Storchaka in branch 'default':
Issue #28255: calendar.TextCalendar().prmonth() no longer prints a space
https://hg.python.org/cpython/rev/049e58f74272
msg279397 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-10-25 12:21
New changeset 4a3892f49e1a by Serhiy Storchaka in branch 'default':
Issue #28255: calendar.TextCalendar.prweek() no longer prints a space after
https://hg.python.org/cpython/rev/4a3892f49e1a
msg279398 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-25 12:23
prweek() and pryear() are changed only in 3.7. If this breaks somebody's code, there is enough time to update this code or rollback changes.
History
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72442
2017-03-31 16:36:29dstufftsetpull_requests: + pull_request1027
2016-10-25 12:23:07serhiy.storchakasetstatus: open -> closed
messages: + msg279398

assignee: serhiy.storchaka
resolution: fixed
stage: patch review -> resolved
2016-10-25 12:21:20python-devsetmessages: + msg279397
2016-10-25 12:04:31python-devsetnosy: + python-dev
messages: + msg279396
2016-10-04 17:52:33serhiy.storchakasetmessages: + msg278070
2016-09-28 17:48:18belopolskysetnosy: + belopolsky
2016-09-26 19:09:09serhiy.storchakasetmessages: + msg277451
2016-09-23 11:07:24xiang.zhangsetmessages: + msg277269
2016-09-23 10:16:25xiang.zhangsetmessages: - msg277263
2016-09-23 09:54:55xiang.zhangsetfiles: + calendar_whitespace_v2.patch

messages: + msg277263
2016-09-23 09:15:30serhiy.storchakasetmessages: + msg277260
2016-09-23 09:02:27serhiy.storchakasettype: enhancement -> behavior
messages: + msg277258
versions: + Python 3.5
2016-09-23 08:51:07xiang.zhangcreate