Skip to content

Commit 8167a96

Browse files
committed
Fix formatting of lambda participating in dot chain, fixes #334
1 parent 31ae4f4 commit 8167a96

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

gdtoolkit/formatter/expression.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,18 @@ def _format_dot_chain_to_multiple_lines_bottom_up(
746746
context: Context,
747747
) -> FormattedLines:
748748
last_chain_element = dot_chain.children[-1]
749-
if isinstance(last_chain_element, Token) or last_chain_element.data not in [
750-
"actual_getattr_call",
751-
"actual_subscr_expr",
752-
]:
749+
if (
750+
isinstance(last_chain_element, Token)
751+
or last_chain_element.data
752+
not in [
753+
"actual_getattr_call",
754+
"actual_subscr_expr",
755+
]
756+
or (
757+
last_chain_element.data == "actual_getattr_call"
758+
and any(expression_contains_lambda(e) for e in dot_chain.children[:-1])
759+
)
760+
):
753761
return _format_operator_chain_based_expression_to_multiple_lines(
754762
dot_chain, expression_context, context
755763
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class WeaponSystemBullet extends Node:
2+
pass
3+
func foo():
4+
var bullet_scene
5+
assert(
6+
(func() -> bool:
7+
var test_instance: Node = bullet_scene.instantiate()
8+
var is_needed_class: bool = test_instance is WeaponSystemBullet
9+
test_instance.free()
10+
return is_needed_class)
11+
.call()
12+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class WeaponSystemBullet:
2+
extends Node
3+
pass
4+
5+
6+
func foo():
7+
var bullet_scene
8+
assert(
9+
(
10+
(func() -> bool:
11+
var test_instance: Node = bullet_scene.instantiate()
12+
var is_needed_class: bool = test_instance is WeaponSystemBullet
13+
test_instance.free()
14+
return is_needed_class)
15+
. call()
16+
)
17+
)

0 commit comments

Comments
 (0)