mirror of https://github.com/python/cpython.git
If a function contains a doc string, remove the doc string node from
the function's body. If assert is used without an error message, make the AST node None rather than Name('None').
This commit is contained in:
parent
d3d7bb1c31
commit
a59ac0a7df
|
@ -173,6 +173,10 @@ def funcdef(self, nodelist):
|
|||
# code for function
|
||||
code = self.com_node(nodelist[4])
|
||||
|
||||
if doc is not None:
|
||||
assert isinstance(code, Stmt)
|
||||
assert isinstance(code.nodes[0], Discard)
|
||||
del code.nodes[0]
|
||||
n = Function(name, names, defaults, flags, doc, code)
|
||||
n.lineno = lineno
|
||||
return n
|
||||
|
@ -400,7 +404,7 @@ def assert_stmt(self, nodelist):
|
|||
if (len(nodelist) == 4):
|
||||
expr2 = self.com_node(nodelist[3])
|
||||
else:
|
||||
expr2 = Name('None')
|
||||
expr2 = None
|
||||
n = Assert(expr1, expr2)
|
||||
n.lineno = nodelist[0][2]
|
||||
return n
|
||||
|
|
|
@ -173,6 +173,10 @@ def funcdef(self, nodelist):
|
|||
# code for function
|
||||
code = self.com_node(nodelist[4])
|
||||
|
||||
if doc is not None:
|
||||
assert isinstance(code, Stmt)
|
||||
assert isinstance(code.nodes[0], Discard)
|
||||
del code.nodes[0]
|
||||
n = Function(name, names, defaults, flags, doc, code)
|
||||
n.lineno = lineno
|
||||
return n
|
||||
|
@ -400,7 +404,7 @@ def assert_stmt(self, nodelist):
|
|||
if (len(nodelist) == 4):
|
||||
expr2 = self.com_node(nodelist[3])
|
||||
else:
|
||||
expr2 = Name('None')
|
||||
expr2 = None
|
||||
n = Assert(expr1, expr2)
|
||||
n.lineno = nodelist[0][2]
|
||||
return n
|
||||
|
|
Loading…
Reference in New Issue