Skip to content

Commit

Permalink
docstring extraction in python3.8 needs tweaking. vega#1781
Browse files Browse the repository at this point in the history
  • Loading branch information
osuchw committed Nov 11, 2019
1 parent b98ab5b commit 16e2873
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions altair/sphinxext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,16 @@ def get_docstring_and_rest(filename):
except AttributeError:
# this block can be removed when python 3.6 support is dropped
if node.body and isinstance(node.body[0], ast.Expr) and \
isinstance(node.body[0].value, ast.Str):
isinstance(node.body[0].value, (ast.Str, ast.Constant)):
docstring_node = node.body[0]
docstring = docstring_node.value.s
# python2.7: Code was read in bytes needs decoding to utf-8
# unless future unicode_literals is imported in source which
# make ast output unicode strings
if hasattr(docstring, 'decode') and not isinstance(docstring, six.text_type):
docstring = docstring.decode('utf-8')
lineno = docstring_node.lineno # The last line of the string.
# python3.8: has end_lineno
lineno = getattr(docstring_node, 'end_lineno', None) or docstring_node.lineno # The last line of the string.
# This get the content of the file after the docstring last line
# Note: 'maxsplit' argument is not a keyword argument in python2
rest = content.split('\n', lineno)[-1]
Expand Down

0 comments on commit 16e2873

Please sign in to comment.