Skip to content

Issue 4575 ast get docstring return type #4595

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

Merged

Conversation

mitch292
Copy link
Contributor

@mitch292 mitch292 commented Oct 2, 2020

Resolves #4575

get_docstring can return None in >= 3.6.

cc: @blueyed & @JelleZijlstra

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! You'll want to address the CI lint failures.

Also the version check is incorrect, Python 3.5 returns None sometimes as well (it's just not as visible because the 3.5 source doesn't seem to be PEP8-compliant in this case). But you can demonstrate this empirically as well:

~ λ python3.5                                
Python 3.5.9 (default, Jun 11 2020, 19:03:06) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> mod = ast.parse("def f(): ...")
>>> mod.body
[<_ast.FunctionDef object at 0x1076dd080>]
>>> mod.body[0]
<_ast.FunctionDef object at 0x1076dd080>
>>> ast.get_docstring(mod.body[0])
>>> ast.get_docstring(mod.body[0]) is None
True

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the version check :-) It's good the way you had it on your first commit

@hauntsaninja hauntsaninja merged commit 8427e09 into python:master Oct 2, 2020
@hauntsaninja
Copy link
Collaborator

Thanks again!

@mitch292
Copy link
Contributor Author

mitch292 commented Oct 2, 2020

Thanks for the help @hauntsaninja !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ast.get_docstring: wrong return type
2 participants