Closed tacaswell closed 4 years ago
Thanks @tacaswell for the report!
OK the first problem I see is that slices are now expressions and location information has been added which has fixed behaviour in both asttokens and ast
:
import ast
from asttokens import ASTTokens
source = """
x[1:2]
"""
tree = ast.parse(source)
print(ast.dump(tree))
node = tree.body[0].value.slice
print(ast.dump(node))
print(f"{ast.get_source_segment(source, node)=}")
atok = ASTTokens(source, tree=tree)
print(f"{atok.get_text(node)=}")
print(f"{ast.Slice.__base__=}")
In Python 3.8:
ast.get_source_segment(source, node)=None
atok.get_text(node)='2'
ast.Slice.__base__=<class '_ast.slice'>
(the exact result of atok.get_text(node)
varies quite a bit with different slices)
In 3.9:
ast.get_source_segment(source, node)=':2'
atok.get_text(node)=':2'
ast.Slice.__base__=<class 'ast.expr'>
Because they're now expressions, the tests try to verify the slice nodes and parse source code like ':2'
which of course is a syntax error.
@dsagal how should we handle this? By far the easiest course is to just ignore slices in tests, as has done before.
Oh and ExtSlice is now represented by Tuple. See https://bugs.python.org/issue34822
Overall, there are 5 astroid failures and 10 regular failures.
If I ignore slices in verify_all_nodes
, then there are 0 astroid failures and 7 regular failures.
The other problem is that keyword nodes have changed: https://bugs.python.org/issue40141
This simple script fails:
import asttokens
asttokens.ASTTokens("""
foo(x=y)
""", parse=1)
If in addition to ignoring slices I remove MarkTokens.visit_keyword
, then there are 2 astroid failures and 0 regular failures!
That's all I have time for now, will look at this again later.
Thank you @alexmojaki !
Awesome! Thank you for the quick fix (even if I only just noticed today)!
There have been changes to the AST upstream in cpython are breaking
asttokens
In addition there seems to have been changes that break
asttokens
in a way that breaksstack-data
which breaks IPython that don't look like they are capture in the tests:Full pytest output:
full IPython traceback
, 140371038733216, 142) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3254, in run_ast_nodes if (await self.run_code(code, result, async_=asy)): File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3348, in run_code self.showtraceback(running_compiled_code=True) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2046, in showtraceback stb = self.InteractiveTB.structured_traceback(etype, File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 977, in structured_traceback return FormattedTB.structured_traceback( File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 877, in structured_traceback return VerboseTB.structured_traceback( File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 734, in structured_traceback formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context, File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 700, in format_exception_as_a_whole records = self.get_records(etb, number_of_lines_of_context, tb_offset) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 728, in get_records return list(stack_data.FrameInfo.stack_data(etb, options=options))[tb_offset:] File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 543, in stack_data yield from collapse_repeated( File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/utils.py", line 80, in collapse_repeated yield from map(mapper, original_group) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 533, in mapper return cls(f, options) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 498, in __init__ self.executing = Source.executing(frame_or_tb) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 263, in executing source = cls.for_frame(frame) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 212, in for_frame return cls.for_filename(frame.f_code.co_filename, frame.f_globals or {}) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 225, in for_filename result = source_cache[filename] = cls(filename, lines) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 81, in __init__ self.asttokens() File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 336, in asttokens return ASTTokens( File "/home/tcaswell/source/other_source/asttokens/asttokens/asttokens.py", line 65, in __init__ self.mark_tokens(self._tree) File "/home/tcaswell/source/other_source/asttokens/asttokens/asttokens.py", line 76, in mark_tokens MarkTokens(self).visit_tree(root_node) File "/home/tcaswell/source/other_source/asttokens/asttokens/mark_tokens.py", line 49, in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) File "/home/tcaswell/source/other_source/asttokens/asttokens/util.py", line 186, in visit_tree ret = postvisit(current, par_value, value) File "/home/tcaswell/source/other_source/asttokens/asttokens/mark_tokens.py", line 92, in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) File "/home/tcaswell/source/other_source/asttokens/asttokens/mark_tokens.py", line 334, in visit_keyword util.expect_token(name, token.NAME, node.arg) File "/home/tcaswell/source/other_source/asttokens/asttokens/util.py", line 56, in expect_token raise ValueError("Expected token %s, got %s on line %s col %s" % ( ValueError: Expected token NAME:'co_flags', got NAME:'new_code' on line 144 col 9 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2044, in showtraceback stb = value._render_traceback_() AttributeError: 'ValueError' object has no attribute '_render_traceback_' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 261, in executing args = executing_cache[key] KeyError: (
, 140371038732864, 690) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2886, in _run_cell return runner(coro) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner coro.send(None) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3062, in run_cell_async has_raised = await self.run_ast_nodes(code_ast.body, cell_name, File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3273, in run_ast_nodes self.showtraceback() File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2046, in showtraceback stb = self.InteractiveTB.structured_traceback(etype, File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 977, in structured_traceback return FormattedTB.structured_traceback( File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 877, in structured_traceback return VerboseTB.structured_traceback( File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 734, in structured_traceback formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context, File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 700, in format_exception_as_a_whole records = self.get_records(etb, number_of_lines_of_context, tb_offset) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 728, in get_records return list(stack_data.FrameInfo.stack_data(etb, options=options))[tb_offset:] File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 543, in stack_data yield from collapse_repeated( File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/utils.py", line 80, in collapse_repeated yield from map(mapper, original_group) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 533, in mapper return cls(f, options) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 498, in __init__ self.executing = Source.executing(frame_or_tb) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 263, in executing source = cls.for_frame(frame) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 212, in for_frame return cls.for_filename(frame.f_code.co_filename, frame.f_globals or {}) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 225, in for_filename result = source_cache[filename] = cls(filename, lines) File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 81, in __init__ self.asttokens() File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 336, in asttokens return ASTTokens( File "/home/tcaswell/source/other_source/asttokens/asttokens/asttokens.py", line 65, in __init__ self.mark_tokens(self._tree) File "/home/tcaswell/source/other_source/asttokens/asttokens/asttokens.py", line 76, in mark_tokens MarkTokens(self).visit_tree(root_node) File "/home/tcaswell/source/other_source/asttokens/asttokens/mark_tokens.py", line 49, in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) File "/home/tcaswell/source/other_source/asttokens/asttokens/util.py", line 186, in visit_tree ret = postvisit(current, par_value, value) File "/home/tcaswell/source/other_source/asttokens/asttokens/mark_tokens.py", line 92, in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) File "/home/tcaswell/source/other_source/asttokens/asttokens/mark_tokens.py", line 334, in visit_keyword util.expect_token(name, token.NAME, node.arg) File "/home/tcaswell/source/other_source/asttokens/asttokens/util.py", line 56, in expect_token raise ValueError("Expected token %s, got %s on line %s col %s" % ( ValueError: Expected token NAME:'co_flags', got NAME:'new_code' on line 144 col 9 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2044, in showtraceback stb = value._render_traceback_() AttributeError: 'ValueError' object has no attribute '_render_traceback_' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 261, in executing args = executing_cache[key] KeyError: (
, 140371038702208, 60) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/tcaswell/.virtualenvs/bleeding/bin/ipython", line 8, in
sys.exit(start_ipython())
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/__init__.py", line 126, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/traitlets/config/application.py", line 664, in launch_instance
app.start()
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/terminal/ipapp.py", line 356, in start
self.shell.mainloop()
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/terminal/interactiveshell.py", line 559, in mainloop
self.interact()
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/terminal/interactiveshell.py", line 550, in interact
self.run_cell(code, store_history=True)
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2857, in run_cell
result = self._run_cell(
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2891, in _run_cell
self.showtraceback(running_compiled_code=True)
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2046, in showtraceback
stb = self.InteractiveTB.structured_traceback(etype,
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 977, in structured_traceback
return FormattedTB.structured_traceback(
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 877, in structured_traceback
return VerboseTB.structured_traceback(
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 734, in structured_traceback
formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 700, in format_exception_as_a_whole
records = self.get_records(etb, number_of_lines_of_context, tb_offset)
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/ultratb.py", line 728, in get_records
return list(stack_data.FrameInfo.stack_data(etb, options=options))[tb_offset:]
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 543, in stack_data
yield from collapse_repeated(
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/utils.py", line 80, in collapse_repeated
yield from map(mapper, original_group)
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 533, in mapper
return cls(f, options)
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 498, in __init__
self.executing = Source.executing(frame_or_tb)
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 263, in executing
source = cls.for_frame(frame)
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 212, in for_frame
return cls.for_filename(frame.f_code.co_filename, frame.f_globals or {})
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 225, in for_filename
result = source_cache[filename] = cls(filename, lines)
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/stack_data/core.py", line 81, in __init__
self.asttokens()
File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.9/site-packages/executing.py", line 336, in asttokens
return ASTTokens(
File "/home/tcaswell/source/other_source/asttokens/asttokens/asttokens.py", line 65, in __init__
self.mark_tokens(self._tree)
File "/home/tcaswell/source/other_source/asttokens/asttokens/asttokens.py", line 76, in mark_tokens
MarkTokens(self).visit_tree(root_node)
File "/home/tcaswell/source/other_source/asttokens/asttokens/mark_tokens.py", line 49, in visit_tree
util.visit_tree(node, self._visit_before_children, self._visit_after_children)
File "/home/tcaswell/source/other_source/asttokens/asttokens/util.py", line 186, in visit_tree
ret = postvisit(current, par_value, value)
File "/home/tcaswell/source/other_source/asttokens/asttokens/mark_tokens.py", line 92, in _visit_after_children
nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last)
File "/home/tcaswell/source/other_source/asttokens/asttokens/mark_tokens.py", line 334, in visit_keyword
util.expect_token(name, token.NAME, node.arg)
File "/home/tcaswell/source/other_source/asttokens/asttokens/util.py", line 56, in expect_token
raise ValueError("Expected token %s, got %s on line %s col %s" % (
ValueError: Expected token NAME:'co_flags', got NAME:'new_code' on line 144 col 9
If you suspect this is an IPython 8.0.0.dev bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True
```
attn @alexmojaki @Carreau