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

argparse breaks long lines on NO-BREAK SPACE #73476

Closed
stevendaprano opened this issue Jan 17, 2017 · 11 comments
Closed

argparse breaks long lines on NO-BREAK SPACE #73476

stevendaprano opened this issue Jan 17, 2017 · 11 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@stevendaprano
Copy link
Member

BPO 29290
Nosy @stevendaprano, @vadmium, @serhiy-storchaka, @wimglenn, @zhangyangyu
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • argparse_nobreak.py
  • argparse-help-non-breaking-spaces.patch
  • argparse-help-non-breaking-spaces-2.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/zhangyangyu'
    closed_at = <Date 2017-01-22.06:45:22.072>
    created_at = <Date 2017-01-17.03:08:41.327>
    labels = ['3.7', 'type-bug', 'library']
    title = 'argparse breaks long lines on NO-BREAK SPACE'
    updated_at = <Date 2017-05-11.05:18:55.626>
    user = 'https://github.com/stevendaprano'

    bugs.python.org fields:

    activity = <Date 2017-05-11.05:18:55.626>
    actor = 'xiang.zhang'
    assignee = 'xiang.zhang'
    closed = True
    closed_date = <Date 2017-01-22.06:45:22.072>
    closer = 'xiang.zhang'
    components = ['Library (Lib)']
    creation = <Date 2017-01-17.03:08:41.327>
    creator = 'steven.daprano'
    dependencies = []
    files = ['46311', '46312', '46376']
    hgrepos = []
    issue_num = 29290
    keywords = ['patch']
    message_count = 11.0
    messages = ['285607', '285608', '285609', '285610', '285611', '285984', '285991', '285994', '285995', '293472', '293473']
    nosy_count = 9.0
    nosy_names = ['roysmith', 'peter.otten', 'steven.daprano', 'python-dev', 'martin.panter', 'paul.j3', 'serhiy.storchaka', 'wim.glenn', 'xiang.zhang']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29290'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @stevendaprano
    Copy link
    Member Author

    argparse help incorrectly breaks long lines on U+u00A0 NO-BREAK SPACE.

    The attached script has been run on Python 3.5.3rc1 in a terminal window 80 columns wide, and it produces output::

    usage: argparse_nobreak.py [-h] [--no-condensedxxxx]
    
    optional arguments:
      -h, --help          show this help message and exit
      --no-condensedxxxx  Disable default font-style: condensed. Also disables "M+
                          1M" condensed monospace.
    

    I expected the last line should have broken just before the "M+ 1M", rather than in the middle.

    See also bpo-20491.

    @stevendaprano stevendaprano added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 17, 2017
    @stevendaprano
    Copy link
    Member Author

    Here's a slightly simpler demo, without the (fortunately harmless) typo.

    @vadmium
    Copy link
    Member

    vadmium commented Jan 17, 2017

    Maybe a duplicate of bpo-16623

    @zhangyangyu
    Copy link
    Member

    textwrap has been fixed in bpo-20491 but this problem still exists. The reason seems to be that argparse replaces the non-break spaces with spaces:

    before self.whitespace_matcher.sub
    'Disable default font-style: condensed. Also disables "M+\\xa01M" condensed monospace.'
    after self.whitespace_matcher.sub
    'Disable default font-style: condensed. Also disables "M+ 1M" condensed monospace.'

    @zhangyangyu
    Copy link
    Member

    I think this is a regression when coming to 3.x. In 2.7, r'\s+' is by default in ASCII mode and won't match unicode non-breaking spaces. In 3.x it's by default unicode mode so non-breaking spaces are replaced by spaces. I think we can just use [ \t\n\r\f\v]+.

    Since here are more active core devs I am going to close bpo-16623 and move this forward here.

    @zhangyangyu zhangyangyu added the 3.7 (EOL) end of life label Jan 17, 2017
    @zhangyangyu
    Copy link
    Member

    v2 addresses the comments. I didn't receive the review notification mail so just saw them today. :-(

    @serhiy-storchaka
    Copy link
    Member

    LGTM.

    You perhaps need to change your email provider Xiang. It fails too often.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 22, 2017

    New changeset 98cde683b9c6 by Xiang Zhang in branch '3.5':
    Issue bpo-29290: argparse help messages won't wrap at non-breaking spaces.
    https://hg.python.org/cpython/rev/98cde683b9c6

    New changeset 1754722ec296 by Xiang Zhang in branch '3.6':
    Issue bpo-29290: Merge 3.5.
    https://hg.python.org/cpython/rev/1754722ec296

    New changeset c47a72627f0c by Xiang Zhang in branch 'default':
    Issue bpo-29290: Merge 3.6.
    https://hg.python.org/cpython/rev/c47a72627f0c

    @zhangyangyu
    Copy link
    Member

    Thanks Serhiy.

    BTW, bpo-16623 is about 2.7 and the cause is wrap doesn't handle unicode non-breaking spaces right. So it's not the same thing as here.

    @wimglenn
    Copy link
    Mannequin

    wimglenn mannequin commented May 11, 2017

    The test "test_help_non_breaking_spaces" from Zhang's commit fails on my platform (other 1563 tests in the module all pass).

    Interestingly, if running the entire test suite, it doesn't fail. It's only when executing the test_argparse.py module directly that causes the failure.

    I guess there is some mutable state, or the test doesn't entirely setup correctly.

    @zhangyangyu
    Copy link
    Member

    I can't reproduce the failure in anyway. :-( Could you do some investigation and give more info?

    @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

    4 participants