diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-05-31 16:26:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 16:26:16 -0700 |
commit | b425d887aa51c8e7900b08cb8df457f450f6fbfd (patch) | |
tree | a18fa96d7d6a1659f5cbf30e699fc5298acfee0d /Parser | |
parent | gh-69093: Fix Setup.local.in rule for _sqlite3 (GH-93380) (diff) | |
download | cpython-b425d887aa51c8e7900b08cb8df457f450f6fbfd.tar.gz cpython-b425d887aa51c8e7900b08cb8df457f450f6fbfd.tar.bz2 cpython-b425d887aa51c8e7900b08cb8df457f450f6fbfd.zip |
gh-92597: Ensure that AST nodes without explicit end positions can be compiled (GH-93359)
(cherry picked from commit 705eaec28f7bee530b1c1635ba385a49a1feaf32)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rwxr-xr-x | Parser/asdl_c.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 3bfe320fe3b..1101a3593df 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -488,6 +488,12 @@ class Obj2ModPrototypeVisitor(PickleVisitor): class Obj2ModVisitor(PickleVisitor): + + attribute_special_defaults = { + "end_lineno": "lineno", + "end_col_offset": "col_offset", + } + @contextmanager def recursive_call(self, node, level): self.emit('if (_Py_EnterRecursiveCall(" while traversing \'%s\' node")) {' % node, level, reflow=False) @@ -637,7 +643,13 @@ class Obj2ModVisitor(PickleVisitor): self.emit("if (tmp == NULL || tmp == Py_None) {", depth) self.emit("Py_CLEAR(tmp);", depth+1) if self.isNumeric(field): - self.emit("%s = 0;" % field.name, depth+1) + if field.name in self.attribute_special_defaults: + self.emit( + "%s = %s;" % (field.name, self.attribute_special_defaults[field.name]), + depth+1, + ) + else: + self.emit("%s = 0;" % field.name, depth+1) elif not self.isSimpleType(field): self.emit("%s = NULL;" % field.name, depth+1) else: |