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

Escape sequences in doc string of ast._pad_whitespace #83705

Closed
mpheath mannequin opened this issue Feb 2, 2020 · 9 comments
Closed

Escape sequences in doc string of ast._pad_whitespace #83705

mpheath mannequin opened this issue Feb 2, 2020 · 9 comments
Labels
3.8 only security fixes 3.9 only security fixes easy type-bug An unexpected behavior, bug, or error

Comments

@mpheath
Copy link
Mannequin

mpheath mannequin commented Feb 2, 2020

BPO 39524
Nosy @ericvsmith, @serhiy-storchaka, @miss-islington, @amiremohamadi, @mpheath, @iritkatriel
PRs
  • bpo-39524: Fixed doc-string in ast._pad_whitespace #18340
  • Fix issue 39524 v3.8.1 #18341
  • bpo-39524: Fixed doc-string in ast._pad_whitespace #18342
  • [3.8] bpo-39524: Fixed doc-string in ast._pad_whitespace (GH-18340) #22857
  • 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 = None
    closed_at = <Date 2020-10-21.16:22:40.563>
    created_at = <Date 2020-02-02.04:09:48.889>
    labels = ['easy', 'type-bug', '3.8', '3.9']
    title = 'Escape sequences in doc string of ast._pad_whitespace'
    updated_at = <Date 2020-10-21.16:22:40.563>
    user = 'https://github.com/mpheath'

    bugs.python.org fields:

    activity = <Date 2020-10-21.16:22:40.563>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-10-21.16:22:40.563>
    closer = 'iritkatriel'
    components = []
    creation = <Date 2020-02-02.04:09:48.889>
    creator = 'mpheath'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39524
    keywords = ['patch', 'easy', 'newcomer friendly']
    message_count = 9.0
    messages = ['361203', '361204', '361205', '361246', '361289', '361335', '361967', '377193', '379217']
    nosy_count = 6.0
    nosy_names = ['eric.smith', 'serhiy.storchaka', 'miss-islington', 'Amir', 'mpheath', 'iritkatriel']
    pr_nums = ['18340', '18341', '18342', '22857']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39524'
    versions = ['Python 3.8', 'Python 3.9']

    @mpheath
    Copy link
    Mannequin Author

    mpheath mannequin commented Feb 2, 2020

    In the ast module, a function named _pad_whitespace has a doc string with escape sequences of \f and \t.

    The current doc string from Lib/ast.py:305 is:

    """Replace all chars except '\f\t' in a line with spaces."""
    

    Example of doc string output in a REPL:

        Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
        Type "help", "copyright", "credits" or "license" for more information.
        >>> import ast
        >>> import inspect
        >>> inspect.getdoc(ast._pad_whitespace)
        "Replace all chars except '\x0c     ' in a line with spaces."
        >>>

    The \x0c is the formfeed and the ' ' (5 spaces) was the tab.

    It is my understanding that the output should be:

    "Replace all chars except '\f\t' in a line with spaces."
    

    I would expect the source to be:

    """Replace all chars except '\\f\\t' in a line with spaces."""
    

    or perhaps a raw string:

    r"""Replace all chars except '\f\t' in a line with spaces."""
    

    The current Lib/ast.py:305 is Python 3.9.0 alpha 3 though the issue is also in Python 3.8.0 and 3.8.1 with 3.8/Lib/ast.py:227 .
    Python 3.7.4 3.7/Lib/ast.py does not have the function _pad_whitespace as it appears major code changes occurred in the ast module with Python 3.8.0.

    @mpheath mpheath mannequin added 3.8 only security fixes 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Feb 2, 2020
    @mpheath
    Copy link
    Mannequin Author

    mpheath mannequin commented Feb 2, 2020

    Correction: Python 3.8.0 and 3.8.1 with Lib/ast.py:277

    Line 227 is invalid and 277 is correct.

    @mpheath
    Copy link
    Mannequin Author

    mpheath mannequin commented Feb 2, 2020

    Correction: Python 3.8.0 and 3.8.1 with 3.8/Lib/ast.py:277

    Line 227 is invalid and 277 is correct and forgot to add 3.8 prefix. Sorry.

    @ericvsmith
    Copy link
    Member

    I think this would be an improvement, and an good issue for a newcomer.

    I'd vote for the r-string, but it doesn't really matter.

    @amiremohamadi
    Copy link
    Mannequin

    amiremohamadi mannequin commented Feb 3, 2020

    But in both cases the 'Output' will contain '\\':
    "Replace all chars except '\\f\\t' in a line with spaces."

    @mpheath
    Copy link
    Mannequin Author

    mpheath mannequin commented Feb 4, 2020

    I have submitted 2 Pull Requests. One for 3.9 and the other for 3.8. Only way I knew was to create 2 separate branches to checkout, linked to version tags to get the correct patches for ast.py. Hope is OK.

    @serhiy-storchaka
    Copy link
    Member

    New changeset fbeba8f by mpheath in branch 'master':
    bpo-39524: Fixed doc-string in ast._pad_whitespace (GH-18340)
    fbeba8f

    @iritkatriel
    Copy link
    Member

    The backport of the patch to 3.8 has failed.

    @miss-islington
    Copy link
    Contributor

    New changeset f3982d6 by Irit Katriel in branch '3.8':
    [3.8] bpo-39524: Fixed doc-string in ast._pad_whitespace (GH-18340) (GH-22857)
    f3982d6

    @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.8 only security fixes 3.9 only security fixes easy type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants