-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Hello,
Thank you for your work and great product you maintain for a lot of users like me!
I get some code that started to fail after upgrading to v 4.0.0. I see there are some breaking changes in (https://github.com/boolangery/py-lua-parser/releases/tag/4.0.0). I'm not sure I hit one of those cases, and wanted to ask if the parsing I see is expected.
We are talking about tables initializers for lists or sequences:
t = {"a", "b"}
this creates a table with numeric indexes, 1, 2. We can iterate on this table using pairs or ipairs (while example in this test that is expected to fail fails indeed standalone-tests/failing/luau-table-iteration.lua)
for k, v in pairs(t) do
print(k.." => "..v)
end
In version 4.0.0 Field keys of the table in the example above are all None:
For slightly modified code from the example in docs:
from luaparser import ast
from luaparser import astnodes
src = open('t.lua', 'r').read()
print(src)
class StrVisitor(ast.ASTVisitor):
def visit_Field(self, node):
print('Field key = ' + str(node.key))
tree = ast.parse(src)
StrVisitor().visit(tree)
output is:
Field key = None
Field key = None
Is this expected, and I should expect the same behavior in future versions?
There is also a bug in command line tool, while parsing code t = {"a", "b"}:
luaparser t.lua
Traceback (most recent call last):
File "/private/tmp/luaparser/.venv/lib/python3.14/site-packages/luaparser/ast.py", line 86, in default
to_json = getattr(o, "to_json")
AttributeError: 'bytes' object has no attribute 'to_json'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/private/tmp/luaparser/.venv/bin/luaparser", line 7, in <module>
sys.exit(main())
~~~~^^
File "/private/tmp/luaparser/.venv/lib/python3.14/site-packages/luaparser/__main__.py", line 73, in main
output = ast.to_pretty_json(tree)
File "/private/tmp/luaparser/.venv/lib/python3.14/site-packages/luaparser/ast.py", line 95, in to_pretty_json
return json.dumps(root, cls=JSONEncoder, indent=4)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/__init__.py", line 242, in dumps
**kw).encode(obj)
~~~~~~^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/encoder.py", line 202, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/encoder.py", line 263, in iterencode
return _iterencode(o, 0)
File "/private/tmp/luaparser/.venv/lib/python3.14/site-packages/luaparser/ast.py", line 91, in default
return {k: v for k, v in o.__dict__.items() if not k.startswith("_")}
^^^^^^^^^^
AttributeError: 'bytes' object has no attribute '__dict__'. Did you mean: '__dir__'?
when serializing dict item 's'
when serializing luaparser.astnodes.String object
when serializing dict item 'value'
when serializing luaparser.astnodes.Field object
when serializing list item 0
when serializing dict item 'fields'
when serializing luaparser.astnodes.Table object
when serializing list item 0
when serializing dict item 'values'
when serializing luaparser.astnodes.Assign object
when serializing list item 0
when serializing dict item 'body'
when serializing luaparser.astnodes.Block object
when serializing dict item 'body'
when serializing luaparser.astnodes.Chunk object
Thank you!