diff --git a/rewrite/rewrite/python/_parser_visitor.py b/rewrite/rewrite/python/_parser_visitor.py index 2445583..67821a8 100644 --- a/rewrite/rewrite/python/_parser_visitor.py +++ b/rewrite/rewrite/python/_parser_visitor.py @@ -1039,10 +1039,6 @@ def visit_Call(self, node): if isinstance(node.func, ast.Name): select = None name = cast(j.Identifier, self.__convert(node.func)) - elif isinstance(node.func, ast.Call): - select = self.__pad_right(cast(Expression, self.__convert(node.func)), self.__whitespace()) - # printer handles empty name by not printing `.` before it - name = self.__convert_name('') elif isinstance(node.func, ast.Attribute): select = self.__pad_right(self.__convert(node.func.value), self.__source_before('.')) name = j.Identifier( @@ -1054,8 +1050,12 @@ def visit_Call(self, node): self.__map_type(node.func.value), None ) + elif isinstance(node.func, (ast.Call, ast.Subscript)): + select = self.__pad_right(cast(Expression, self.__convert(node.func)), self.__whitespace()) + # printer handles empty name by not printing `.` before it + name = self.__convert_name('') else: - raise NotImplementedError("Calls to functions other than methods are not yet supported") + raise NotImplementedError(f"Calls to functions other than methods are not yet supported: {type(node.func)}") all_args = node.args + node.keywords args = JContainer( diff --git a/rewrite/rewrite/python/parser.py b/rewrite/rewrite/python/parser.py index 4065818..8f622bf 100644 --- a/rewrite/rewrite/python/parser.py +++ b/rewrite/rewrite/python/parser.py @@ -1,5 +1,5 @@ import ast -import traceback +import logging from pathlib import Path from typing import Iterable, Optional @@ -8,6 +8,8 @@ from ._parser_visitor import ParserVisitor from .tree import CompilationUnit +logging.basicConfig(level=logging.ERROR) + class PythonParser(Parser): def parse_inputs(self, sources: Iterable[ParserInput], relative_to: Optional[Path], @@ -20,7 +22,7 @@ def parse_inputs(self, sources: Iterable[ParserInput], relative_to: Optional[Pat cu = ParserVisitor(source_str).visit(tree) cu = require_print_equals_input(self, cu, source, relative_to, ctx) except Exception as e: - traceback.print_exc() + logging.error(f"An error was encountered while parsing {source.path}: {str(e)}", exc_info=True) cu = ParseError.build(self, source, relative_to, ctx, e) yield cu diff --git a/rewrite/tests/python/all/method_invocation_test.py b/rewrite/tests/python/all/method_invocation_test.py index 925b8ea..96d4133 100644 --- a/rewrite/tests/python/all/method_invocation_test.py +++ b/rewrite/tests/python/all/method_invocation_test.py @@ -18,6 +18,11 @@ def test_invoke_function_receiver(): rewrite_run(python("assert a(0)(1)")) +def test_invoke_array_access_receiver(): + # language=python + rewrite_run(python("assert a[0](1)")) + + def test_sequence_unpack(): # language=python rewrite_run(