1
0
forked from VimPlug/jedi

introduce maybe_docstr in parse_statement, which should have been introduced way earlier.

This commit is contained in:
Dave Halter
2014-08-12 17:13:14 +02:00
parent fb1dba269a
commit 6f018e4884
2 changed files with 21 additions and 4 deletions

View File

@@ -273,7 +273,8 @@ class Parser(object):
return pr.Class(self.module, cname, superclasses, first_pos) return pr.Class(self.module, cname, superclasses, first_pos)
def _parse_statement(self, pre_used_token=None, added_breaks=None, def _parse_statement(self, pre_used_token=None, added_breaks=None,
stmt_class=pr.Statement, names_are_set_vars=False): stmt_class=pr.Statement, names_are_set_vars=False,
maybe_docstr=False):
""" """
Parses statements like:: Parses statements like::
@@ -368,7 +369,7 @@ class Parser(object):
first_tok = tok_list[0] first_tok = tok_list[0]
# docstrings # docstrings
if len(tok_list) == 1 and isinstance(first_tok, tokenize.Token) \ if len(tok_list) == 1 and isinstance(first_tok, tokenize.Token) \
and first_tok.type == tokenize.STRING: and first_tok.type == tokenize.STRING and maybe_docstr:
# Normal docstring check # Normal docstring check
if self.freshscope and not self.no_docstr: if self.freshscope and not self.no_docstr:
self._scope.add_docstr(first_tok) self._scope.add_docstr(first_tok)
@@ -376,7 +377,7 @@ class Parser(object):
# Attribute docstring (PEP 224) support (sphinx uses it, e.g.) # Attribute docstring (PEP 224) support (sphinx uses it, e.g.)
# If string literal is being parsed... # If string literal is being parsed...
elif first_tok.type == tokenize.STRING: else:
with common.ignored(IndexError, AttributeError): with common.ignored(IndexError, AttributeError):
# ...then set it as a docstring # ...then set it as a docstring
self._scope.statements[-1].add_docstr(first_tok) self._scope.statements[-1].add_docstr(first_tok)
@@ -604,7 +605,8 @@ class Parser(object):
# this is the main part - a name can be a function or a # this is the main part - a name can be a function or a
# normal var, which can follow anything. but this is done # normal var, which can follow anything. but this is done
# by the statement parser. # by the statement parser.
stmt, tok = self._parse_statement(self._gen.current) stmt, tok = self._parse_statement(self._gen.current,
maybe_docstr=True)
if stmt: if stmt:
self._scope.add_statement(stmt) self._scope.add_statement(stmt)
self.freshscope = False self.freshscope = False

View File

@@ -81,6 +81,19 @@ def elif_flows3(x):
#? int() set #? int() set
elif_flows3(1) elif_flows3(1)
# -----------------
# mid-difficulty if statements
# -----------------
def check(a):
if a is None:
return 1
return ''
#? int()
check(None)
#? str()
check('asb')
# ----------------- # -----------------
# name resolution # name resolution
# ----------------- # -----------------
@@ -108,3 +121,5 @@ else:
#? int #? int
a a