Skip to content
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

TextCalendar.prweek/month/year outputs an extra whitespace character #72442

Closed
zhangyangyu opened this issue Sep 23, 2016 · 9 comments
Closed
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@zhangyangyu
Copy link
Member

BPO 28255
Nosy @abalkin, @serhiy-storchaka, @zhangyangyu
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • calendar_whitespace.patch
  • calendar_whitespace_v2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-10-25.12:23:07.504>
    created_at = <Date 2016-09-23.08:51:07.782>
    labels = ['3.7', 'type-bug', 'library']
    title = 'TextCalendar.prweek/month/year outputs an extra whitespace character'
    updated_at = <Date 2017-03-31.16:36:29.925>
    user = 'https://github.com/zhangyangyu'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:29.925>
    actor = 'dstufft'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-10-25.12:23:07.504>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2016-09-23.08:51:07.782>
    creator = 'xiang.zhang'
    dependencies = []
    files = ['44790', '44791']
    hgrepos = []
    issue_num = 28255
    keywords = ['patch']
    message_count = 9.0
    messages = ['277256', '277258', '277260', '277269', '277451', '278070', '279396', '279397', '279398']
    nosy_count = 4.0
    nosy_names = ['belopolsky', 'python-dev', 'serhiy.storchaka', 'xiang.zhang']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28255'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @zhangyangyu
    Copy link
    Member Author

    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
     >>>

    @zhangyangyu zhangyangyu added type-feature A feature request or enhancement 3.7 (EOL) end of life stdlib Python modules in the Lib dir labels Sep 23, 2016
    @serhiy-storchaka
    Copy link
    Member

    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.

    @serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels Sep 23, 2016
    @serhiy-storchaka
    Copy link
    Member

    prweek() in Python 2 adds a final space. Python 3 version looks correct.

    @zhangyangyu
    Copy link
    Member Author

    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>>>

    @serhiy-storchaka
    Copy link
    Member

    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.

    @serhiy-storchaka
    Copy link
    Member

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 25, 2016

    New changeset 8d54c2a1c796 by Serhiy Storchaka in branch '3.5':
    Issue bpo-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 bpo-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 bpo-28255: calendar.TextCalendar().prmonth() no longer prints a space
    https://hg.python.org/cpython/rev/049e58f74272

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 25, 2016

    New changeset 4a3892f49e1a by Serhiy Storchaka in branch 'default':
    Issue bpo-28255: calendar.TextCalendar.prweek() no longer prints a space after
    https://hg.python.org/cpython/rev/4a3892f49e1a

    @serhiy-storchaka
    Copy link
    Member

    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.

    @serhiy-storchaka serhiy-storchaka self-assigned this Oct 25, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants