mirror of https://github.com/python/cpython
gh-104799: Default missing lists in AST to the empty list (#104834)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
37498fc950
commit
77d2579586
|
@ -1591,6 +1591,8 @@ class ASTValidatorTests(unittest.TestCase):
|
||||||
f = ast.FunctionDef("x", a, [ast.Pass()], [],
|
f = ast.FunctionDef("x", a, [ast.Pass()], [],
|
||||||
ast.Name("x", ast.Store()), None, [])
|
ast.Name("x", ast.Store()), None, [])
|
||||||
self.stmt(f, "must have Load context")
|
self.stmt(f, "must have Load context")
|
||||||
|
f = ast.FunctionDef("x", ast.arguments(), [ast.Pass()])
|
||||||
|
self.stmt(f)
|
||||||
def fac(args):
|
def fac(args):
|
||||||
return ast.FunctionDef("x", args, [ast.Pass()], [], None, None, [])
|
return ast.FunctionDef("x", args, [ast.Pass()], [], None, None, [])
|
||||||
self._check_arguments(fac, self.stmt)
|
self._check_arguments(fac, self.stmt)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Attributes of :mod:`ast` nodes that are lists now default to the empty list
|
||||||
|
if omitted. This means that some code that previously raised
|
||||||
|
:exc:`TypeError` when the AST node was used will now proceed with the empty
|
||||||
|
list instead. Patch by Jelle Zijlstra.
|
|
@ -632,6 +632,15 @@ class Obj2ModVisitor(PickleVisitor):
|
||||||
self.emit(line % field.name, depth)
|
self.emit(line % field.name, depth)
|
||||||
self.emit("return 1;", depth+1)
|
self.emit("return 1;", depth+1)
|
||||||
self.emit("}", depth)
|
self.emit("}", depth)
|
||||||
|
if field.seq:
|
||||||
|
self.emit("if (tmp == NULL) {", depth)
|
||||||
|
self.emit("tmp = PyList_New(0);", depth+1)
|
||||||
|
self.emit("if (tmp == NULL) {", depth+1)
|
||||||
|
self.emit("return 1;", depth+2)
|
||||||
|
self.emit("}", depth+1)
|
||||||
|
self.emit("}", depth)
|
||||||
|
self.emit("{", depth)
|
||||||
|
else:
|
||||||
if not field.opt:
|
if not field.opt:
|
||||||
self.emit("if (tmp == NULL) {", depth)
|
self.emit("if (tmp == NULL) {", depth)
|
||||||
message = "required field \\\"%s\\\" missing from %s" % (field.name, name)
|
message = "required field \\\"%s\\\" missing from %s" % (field.name, name)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue