Skip to content

Commit

Permalink
Fix instantiation of attribute-less AST nodes
Browse files Browse the repository at this point in the history
Fixes #138.
  • Loading branch information
lelit committed Dec 6, 2023
1 parent 40e72fe commit 99b9f4c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Version 5
5.6 (unreleased)
~~~~~~~~~~~~~~~~

- Fix issue `#138`__, a defect that hindered the creation of AST nodes that act as *markers*,
(currently ``A_Star`` and ``CheckPointStmt``), that do not carry any other information

__ https://github.com/lelit/pglast/issues/138

- Use `Cython 3.0.6`__

__ https://github.com/cython/cython/blob/master/CHANGES.rst#306-2023-11-26
Expand Down
8 changes: 6 additions & 2 deletions pglast/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ def __init__(self, data):
v = data.get(a)
if v is not None:
if isinstance(v, dict) and '@' in v:
v = G[v['@']](v)
if len(v) > 1:
v = G[v['@']](v)
else:
v = G[v['@']]()
elif isinstance(v, (tuple, list)):
v = tuple(G[i['@']](i) if isinstance(i, dict) and '@' in i else i
v = tuple((G[i['@']](i) if len(i) > 1 else G[i['@']]())
if isinstance(i, dict) and '@' in i else i
for i in v)
setattr(self, a, v)

Expand Down
5 changes: 5 additions & 0 deletions tests/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@ def test_issue_97():
}
),
})


def test_issue_138():
raw = parse_sql('select * from foo')[0]
ast.RawStmt(raw())
8 changes: 6 additions & 2 deletions tools/extract_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ def __init__(self, data):
v = data.get(a)
if v is not None:
if isinstance(v, dict) and '@' in v:
v = G[v['@']](v)
if len(v) > 1:
v = G[v['@']](v)
else:
v = G[v['@']]()
elif isinstance(v, (tuple, list)):
v = tuple(G[i['@']](i) if isinstance(i, dict) and '@' in i else i
v = tuple((G[i['@']](i) if len(i) > 1 else G[i['@']]())
if isinstance(i, dict) and '@' in i else i
for i in v)
setattr(self, a, v)
Expand Down

0 comments on commit 99b9f4c

Please sign in to comment.