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

3.7 regression: ast.get_docstring() for a node that lacks a docstring #78032

Closed
mgedmin mannequin opened this issue Jun 13, 2018 · 8 comments
Closed

3.7 regression: ast.get_docstring() for a node that lacks a docstring #78032

mgedmin mannequin opened this issue Jun 13, 2018 · 8 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@mgedmin
Copy link
Mannequin

mgedmin mannequin commented Jun 13, 2018

BPO 33851
Nosy @mgedmin, @ned-deily, @methane, @serhiy-storchaka, @miss-islington
PRs
  • bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. #7682
  • [3.7] bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. (GH-7682) #7701
  • 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/ned-deily'
    closed_at = <Date 2018-06-28.01:29:04.069>
    created_at = <Date 2018-06-13.11:25:47.711>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = '3.7 regression: ast.get_docstring() for a node that lacks a docstring'
    updated_at = <Date 2018-06-28.01:29:04.063>
    user = 'https://github.com/mgedmin'

    bugs.python.org fields:

    activity = <Date 2018-06-28.01:29:04.063>
    actor = 'ned.deily'
    assignee = 'ned.deily'
    closed = True
    closed_date = <Date 2018-06-28.01:29:04.069>
    closer = 'ned.deily'
    components = ['Library (Lib)']
    creation = <Date 2018-06-13.11:25:47.711>
    creator = 'mgedmin'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33851
    keywords = ['patch']
    message_count = 8.0
    messages = ['319453', '319455', '319592', '319595', '320339', '320419', '320632', '320640']
    nosy_count = 5.0
    nosy_names = ['mgedmin', 'ned.deily', 'methane', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['7682', '7701']
    priority = None
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33851'
    versions = ['Python 3.7', 'Python 3.8']

    @mgedmin
    Copy link
    Mannequin Author

    mgedmin mannequin commented Jun 13, 2018

    Python 3.7 removes an isinstance(node.body[0], Expr) check ast.get_docstring() that makes it crash when you pass in AST nodes of modules or functions that do not have docstrings.

    Steps to reproduce:

    The failure looks like this:

        Traceback (most recent call last):
          ...
          File "/home/mg/src/findimports/findimports.py", line 337, in find_imports_and_track_names
            visitor.visit(root)
          File "/home/mg/opt/python37/lib/python3.7/ast.py", line 262, in visit
            return visitor(node)
          File "/home/mg/src/findimports/findimports.py", line 169, in visitSomethingWithADocstring
            self.processDocstring(ast.get_docstring(node, clean=False), lineno)
          File "/home/mg/opt/python37/lib/python3.7/ast.py", line 211, in get_docstring
            node = node.body[0].value
        AttributeError: 'Import' object has no attribute 'value'

    @mgedmin mgedmin mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jun 13, 2018
    @serhiy-storchaka
    Copy link
    Member

    I think this fix is worth cherry-picking in 3.7.0.

    @serhiy-storchaka serhiy-storchaka added 3.8 only security fixes release-blocker labels Jun 13, 2018
    @serhiy-storchaka
    Copy link
    Member

    New changeset 08f127a by Serhiy Storchaka in branch 'master':
    bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. (GH-7682)
    08f127a

    @miss-islington
    Copy link
    Contributor

    New changeset a50b825 by Miss Islington (bot) in branch '3.7':
    bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. (GH-7682)
    a50b825

    @ned-deily
    Copy link
    Member

    @mgedmin, Just to be certain, are you able to verify that the change in PR 7701 fixes the problem you see with 3.7.0rc1?

    @mgedmin
    Copy link
    Mannequin Author

    mgedmin mannequin commented Jun 25, 2018

    I've ran my findimports testsuite with CPython's git commit a50b825 and my tests passed, so yes.

    @ned-deily
    Copy link
    Member

    New changeset 235d0fb by Ned Deily (Miss Islington (bot)) in branch '3.7':
    bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. (GH-7682)
    235d0fb

    @ned-deily
    Copy link
    Member

    Fixed in 3.7.0. Thanks, everyone!

    @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 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants