Skip to content

Commit 18e555a

Browse files
python: Fix lambdas after certain characters not working correctly
1 parent cb21b85 commit 18e555a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

electric-operator.el

+3-2
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,9 @@ Also handles C++ lambda capture by reference."
862862

863863
(defun electric-operator-python-mode-in-lambda-args? ()
864864
"Are we inside the arguments statement of a lambda?"
865-
;; \\(\\s-\\|^\\) instead of just \\b because otherwise foo_lambda matches
866-
(electric-operator-looking-back-locally "\\(\\s-\\|^\\)lambda\\s-[^:]*"))
865+
;; We can't just \\b because otherwise foo_lambda matches, so we need a whole
866+
;; explicit list of things that could be before a lambda.
867+
(electric-operator-looking-back-locally "\\([(,:[{=\\s-]\\|^\\)lambda\\s-[^:]*"))
867868

868869
(defun electric-operator-python-mode-: ()
869870
"Handle python dict assignment"

features/python-mode.feature

+5
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ Feature: Python mode basics
176176
When I type "lambda: x, y=1"
177177
Then I should see "lambda: x, y = 1"
178178

179+
Scenario: Space after lambda arguments even inside a function
180+
When I type "foo(lambda x:x"
181+
Then I should see "foo(lambda x: x"
182+
183+
179184
# Slice operator
180185
Scenario: Don't space : inside slices
181186
When I type "a[1:2]"

0 commit comments

Comments
 (0)