Skip to content

Commit 88c0344

Browse files
authored
[Python] Fix tuple detection and unpack operators (#4410)
This commit ensures... 1. unpack operators after opening parenthesis of tuples being scoped correctly 2. correct scope of tuples, if content begins with unpacked sequence
1 parent aaff1d2 commit 88c0344

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Python/Python.sublime-syntax

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,14 @@ contexts:
19861986
maybe-group:
19871987
- match: \(
19881988
scope: punctuation.section.group.begin.python
1989-
set: group-body
1989+
set:
1990+
- group-body
1991+
- maybe-group-begin
1992+
1993+
maybe-group-begin:
1994+
- match: (?=\*)
1995+
fail: generators-groups-and-tuples
1996+
- include: else-pop
19901997

19911998
group-body:
19921999
- meta_scope: meta.group.python
@@ -2000,7 +2007,9 @@ contexts:
20002007
maybe-generator:
20012008
- match: \(
20022009
scope: punctuation.section.sequence.begin.python
2003-
set: generator-body
2010+
set:
2011+
- generator-body
2012+
- allow-unpack-operators
20042013

20052014
generator-body:
20062015
- meta_scope: meta.sequence.generator.python
@@ -2012,7 +2021,9 @@ contexts:
20122021
maybe-tuple:
20132022
- match: \(
20142023
scope: punctuation.section.sequence.begin.python
2015-
set: tuple-body
2024+
set:
2025+
- tuple-body
2026+
- allow-unpack-operators
20162027

20172028
tuple-body:
20182029
- meta_scope: meta.sequence.tuple.python

Python/tests/syntax_test_python.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,14 @@ def f(): pass
27632763
# ^^^^^^^^ meta.expression.generator
27642764
# ^^^ keyword.control.loop.for.generator
27652765
# ^^ keyword.control.loop.in
2766+
2767+
generator = (*i for i in k)
2768+
# ^^^^^^^^^^^^^^^ meta.sequence.generator.python
2769+
# ^ keyword.operator.unpacking.sequence.python
2770+
# ^^^^^^^^ meta.expression.generator.python
2771+
# ^^^ keyword.control.loop.for.generator
2772+
# ^^ keyword.control.loop.in
2773+
27662774
list_ = [i for i in range(100)]
27672775
# ^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence
27682776
# ^^^^^^^^ meta.expression.generator
@@ -2997,9 +3005,13 @@ def f(): pass
29973005
# ^ punctuation.separator.sequence.python
29983006
# ^ keyword.operator.assignment.python
29993007

3008+
t = (*tuple())
3009+
# ^^^^^^^^^^ meta.sequence.tuple.python
3010+
# ^ keyword.operator.unpacking.sequence.python
3011+
30003012
t = (*tuple(), *[1, 2], 3*1)
30013013
# ^^^^^^^^^^^^^^^^^^^^^^ meta.sequence.tuple.python
3002-
# ^ keyword.operator.arithmetic.python
3014+
# ^ keyword.operator.unpacking.sequence.python
30033015
# ^^^^^ support.type.python
30043016
# ^ keyword.operator.unpacking.sequence.python
30053017
# ^ keyword.operator.arithmetic.python

0 commit comments

Comments
 (0)