summaryrefslogtreecommitdiff
path: root/astroid/rebuilder.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-07-06 23:04:02 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2019-07-06 23:04:02 +0300
commita354ae3d9cc7be5509cccf4b1b50c8846c94d8de (patch)
treed3ed5f471f890237e1a622fbdaafd4785406d201 /astroid/rebuilder.py
parent34bd44419112229e2e7aadaf43f3822cff9556c7 (diff)
downloadastroid-git-a354ae3d9cc7be5509cccf4b1b50c8846c94d8de.tar.gz
Grab only Constant strings for docstrings
Diffstat (limited to 'astroid/rebuilder.py')
-rw-r--r--astroid/rebuilder.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py
index da8fd28f..205dd47a 100644
--- a/astroid/rebuilder.py
+++ b/astroid/rebuilder.py
@@ -130,18 +130,16 @@ class TreeRebuilder:
if PY37 and hasattr(node, "docstring"):
doc = node.docstring
return node, doc
- if (
- node.body
- and isinstance(node.body[0], self._parser_module.Expr)
- and isinstance(
- node.body[0].value,
- self._parser_module.Constant if PY38 else self._parser_module.Str,
- )
- ):
- value = node.body[0].value
- doc = value.value if PY38 else value.s
- node.body = node.body[1:]
- return node, doc
+ if node.body and isinstance(node.body[0], self._parser_module.Expr):
+
+ first_value = node.body[0].value
+ if isinstance(first_value, self._parser_module.Str) or (
+ isinstance(first_value, self._parser_module.Constant)
+ and isinstance(first_value.value, str)
+ ):
+ doc = first_value.value if PY38 else first_value.s
+ node.body = node.body[1:]
+ return node, doc
except IndexError:
pass # ast built from scratch
return node, None