Skip to content

Commit

Permalink
[Python] Ensure type comments are exited at newline
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Jul 22, 2020
1 parent e3b57a9 commit 97ae638
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Python/Python.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ contexts:
scope: punctuation.section.brackets.begin.python
set:
- meta_content_scope: comment.line.type-hint.python
- match: \n
pop: true
- match: \[
scope: invalid.illegal.python
- match: '[a-zA-Z_-][a-zA-Z_0-9-]+'
Expand All @@ -465,6 +467,8 @@ contexts:
set:
# Don't allow a second block.
- meta_content_scope: comment.line.type-hint.python
- match: \n
pop: true
- match: '(?=#)'
set: comments-basic
- match: \S
Expand All @@ -474,6 +478,8 @@ contexts:

type-comment:
- meta_content_scope: comment.line.type-hint.python
- match: \n
pop: true
- match: '(?=#)'
set: comments-basic
# Don't use expressions here, only a few types are reasonable
Expand All @@ -489,6 +495,8 @@ contexts:
1: meta.item-access.python punctuation.section.brackets.begin.python
push:
- meta_content_scope: meta.item-access.arguments.python
- match: (?=\n)
pop: true
- match: \]
scope: meta.item-access.python punctuation.section.brackets.end.python
pop: true
Expand All @@ -500,6 +508,8 @@ contexts:
scope: punctuation.section.parens.begin.python
push:
- meta_content_scope: meta.function.parameters.python
- match: (?=\n)
pop: true
- match: \)
scope: punctuation.section.parens.end.python
pop: true
Expand Down
16 changes: 16 additions & 0 deletions Python/syntax_test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,22 @@ def function(a, b, *c, **d):
# ^^^^^^^^^^^^^^^^^^ comment.line.number-sign - comment.line.type-hint
# ^ punctuation.definition.comment
class TypeCommentTest:
member = [] # type: List[dict]
def __del__(self) -> None:
# ^^^^ constant.language
# ^ punctuation.section
pass
# ^^^^ keyword.control
class TypeCommentTest2:
member = [] # type: List[dict]
def __del__(self) -> None:
pass
# ^^^^ keyword.control
##################
# Assignment Expressions
Expand Down

0 comments on commit 97ae638

Please sign in to comment.