Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit 224fc07

Browse files
committed
Support method invocations with receiver in parentheses
1 parent ec1ba4f commit 224fc07

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

rewrite/rewrite/python/_parser_visitor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,23 @@ def visit_Call(self, node):
12031203
self.__map_type(node.func.value),
12041204
None
12051205
)
1206+
save_cursor = self._cursor
1207+
parens_right_padding = self.__whitespace()
1208+
if self.__cursor_at(')'):
1209+
name = j.FieldAccess(
1210+
random_id(),
1211+
Space.EMPTY,
1212+
Markers.EMPTY,
1213+
select.element,
1214+
JLeftPadded(select.after, name, Markers.EMPTY),
1215+
None
1216+
)
1217+
while len(self._parentheses_stack) > 0 and self.__cursor_at(')'):
1218+
self._cursor += 1
1219+
name = self._parentheses_stack.pop()[0](name, parens_right_padding)
1220+
save_cursor = self._cursor
1221+
parens_right_padding = self.__whitespace()
1222+
self._cursor = save_cursor
12061223
else:
12071224
select = self.__pad_right(cast(Expression, self.__convert(node.func)), self.__whitespace())
12081225
# printer handles empty name by not printing `.` before it

rewrite/tests/python/all/method_invocation_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ def test_invoke_function_receiver():
1818
rewrite_run(python("assert a(0)(1)"))
1919

2020

21+
def test_qualified_receiver_with_parens():
22+
# language=python
23+
rewrite_run(
24+
python(
25+
"""
26+
class Foo:
27+
def getter(self, row):
28+
pass
29+
def foo(self):
30+
return (self.getter )(1)
31+
"""
32+
)
33+
)
34+
35+
2136
def test_invoke_lambda_receiver():
2237
# language=python
2338
rewrite_run(python("assert (lambda x: x)(1)"))

0 commit comments

Comments
 (0)