summaryrefslogtreecommitdiff
path: root/astroid/rebuilder.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-02-04 08:35:52 -0500
committerClaudiu Popa <pcmanticore@gmail.com>2018-02-04 08:39:54 -0500
commitd9f1c85b0c8ebd7e88ce76b8f0647b869dac4be0 (patch)
treea1d45657c4bed3cde66cbf608473e5d6f7f1e8a6 /astroid/rebuilder.py
parent363f726e6a42962a0c04e30ade8348b115b40963 (diff)
downloadastroid-git-d9f1c85b0c8ebd7e88ce76b8f0647b869dac4be0.tar.gz
Use the .docstring attribute on Python 3.7 if it exists
This attribute contains now the actual docstring, it is not in the body of the function/class/node as it was until now.
Diffstat (limited to 'astroid/rebuilder.py')
-rw-r--r--astroid/rebuilder.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py
index 7ff62157..d1c9bfed 100644
--- a/astroid/rebuilder.py
+++ b/astroid/rebuilder.py
@@ -71,6 +71,7 @@ REDIRECT = {'arguments': 'Arguments',
}
PY3 = sys.version_info >= (3, 0)
PY34 = sys.version_info >= (3, 4)
+PY37 = sys.version_info >= (3, 7)
CONTEXTS = {_ast.Load: astroid.Load,
_ast.Store: astroid.Store,
_ast.Del: astroid.Del,
@@ -78,11 +79,17 @@ CONTEXTS = {_ast.Load: astroid.Load,
def _get_doc(node):
+
try:
- if isinstance(node.body[0], _ast.Expr) and isinstance(node.body[0].value, _ast.Str):
+ if (node.body
+ and isinstance(node.body[0], _ast.Expr)
+ and isinstance(node.body[0].value, _ast.Str)):
doc = node.body[0].value.s
node.body = node.body[1:]
return node, doc
+ elif PY37 and hasattr(node, 'docstring'):
+ doc = node.docstring
+ return node, doc
except IndexError:
pass # ast built from scratch
return node, None