Skip to content

[BUG] Parsing error with multi-ilne chained methods wrapped in parenthesis #394

@lasagnaphil

Description

@lasagnaphil

Bug description

The parser has trouble understanding multi-line chained methods when being wrapped in parenthesis:

class Thing:
	def do_a(self):
		print("A")
		return self
	def do_b(self):
		print("B")
		return self
	def do_c(self):
		print("C")
		return self
		
(Thing()
	.do_a()
	.do_b()
	.do_c())
Traceback (most recent call last):
  File "main.py", line 19
    .do_a()
SyntaxError: expected ')', got '.'

Which is valid in standard Python, and is a technique often used in these cases.
A workaround for this is to use newlines instead, which works both in pocketpy and standard Python (but feels less ergonomic)

Thing() \
	.do_a() \
	.do_b() \
	.do_c()

Steps to reproduce

You can run the snippet in latest online pocketpy (2025-08-31).
Also tested natively in the latest commit (1ab1750) on macOS (arm64).

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingno-plan

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions