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.

Title: Escape sequences in doc string of ast._pad_whitespace
Type: behavior Stage: resolved
Components: Versions: Python 3.9, Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Amir, eric.smith, iritkatriel, miss-islington, mpheath, serhiy.storchaka
Priority: normal Keywords: easy, newcomer friendly, patch

Created on 2020-02-02 04:09 by mpheath, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18340 merged mpheath, 2020-02-04 00:32
PR 18341 closed mpheath, 2020-02-04 00:58
PR 18342 closed mpheath, 2020-02-04 01:44
PR 22857 merged iritkatriel, 2020-10-21 15:40
Messages (9)
msg361203 - (view) Author: (mpheath) * Date: 2020-02-02 04:09
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/ 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/ is Python 3.9.0 alpha 3 though the issue is also in Python 3.8.0 and 3.8.1 with Lib/ .
Python 3.7.4 Lib/ does not have the function _pad_whitespace as it appears major code changes occurred in the ast module with Python 3.8.0.
msg361204 - (view) Author: (mpheath) * Date: 2020-02-02 04:21
Correction: Python 3.8.0 and 3.8.1 with Lib/

Line 227 is invalid and 277 is correct.
msg361205 - (view) Author: (mpheath) * Date: 2020-02-02 04:23
Correction: Python 3.8.0 and 3.8.1 with Lib/

Line 227 is invalid and 277 is correct and forgot to add 3.8 prefix. Sorry.
msg361246 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-02-02 16:18
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.
msg361289 - (view) Author: Amir Mohamadi (Amir) * Date: 2020-02-03 13:16
But in both cases the 'Output' will contain '\\':
"Replace all chars except '\\f\\t' in a line with spaces."
msg361335 - (view) Author: (mpheath) * Date: 2020-02-04 01:14
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 Hope is OK.
msg361967 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-02-13 18:32
New changeset fbeba8f2481411d608a616366394e07cdc52e0bb by mpheath in branch 'master':
bpo-39524: Fixed doc-string in ast._pad_whitespace (GH-18340)
msg377193 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-09-19 20:49
The backport of the patch to 3.8 has failed.
msg379217 - (view) Author: miss-islington (miss-islington) Date: 2020-10-21 16:21
New changeset f3982d666c1df290373a4810edd501b2176b45c7 by Irit Katriel in branch '3.8':
[3.8] bpo-39524: Fixed doc-string in ast._pad_whitespace (GH-18340) (GH-22857)
Date User Action Args
2022-04-11 14:59:26adminsetgithub: 83705
2020-10-21 16:22:40iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-10-21 16:21:04miss-islingtonsetnosy: + miss-islington
messages: + msg379217
2020-10-21 15:40:08iritkatrielsetpull_requests: + pull_request21800
2020-09-19 20:49:30iritkatrielsetnosy: + iritkatriel
messages: + msg377193
2020-02-13 18:32:13serhiy.storchakasetmessages: + msg361967
2020-02-04 01:44:33mpheathsetpull_requests: + pull_request17714
2020-02-04 01:14:39mpheathsetmessages: + msg361335
2020-02-04 00:58:43mpheathsetpull_requests: + pull_request17713
2020-02-04 00:32:22mpheathsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request17712
2020-02-03 13:16:22Amirsetnosy: + Amir
messages: + msg361289
2020-02-02 16:18:20eric.smithsetnosy: + eric.smith
messages: + msg361246

keywords: + easy, newcomer friendly
stage: needs patch
2020-02-02 04:43:00xtreaksetnosy: + serhiy.storchaka
2020-02-02 04:23:37mpheathsetmessages: + msg361205
2020-02-02 04:21:08mpheathsetmessages: + msg361204
2020-02-02 04:09:48mpheathcreate