Skip to content

Commit

Permalink
[Python] Add support for some new syntax in Python 3.8 (sublimehq#2006)
Browse files Browse the repository at this point in the history
* [Python] Support `=` debug indicator in f-strings

New in Python 3.8.
Upstream change: python/cpython@9a4135e

* [Python] Support "positional args only" operator

Added in Python 3.8 via https://www.python.org/dev/peps/pep-0570/.
  • Loading branch information
FichteFoll authored and mitranim committed Mar 20, 2022
1 parent 7abbdf7 commit bb649b0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Python/Python.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,13 @@ contexts:
- match: ','
scope: punctuation.separator.parameters.python
push: allow-unpack-operators
- match: /
scope: storage.modifier.positional-args-only.python
push:
- match: (?=[,)])
pop: true
- match: \S
scope: invalid.illegal.expected-comma.python
- match: '(?==)'
set:
- match: '='
Expand Down Expand Up @@ -1426,6 +1433,8 @@ contexts:
pop: true
- match: '![ars]'
scope: storage.modifier.conversion.python
- match: =
scope: storage.modifier.debug.python
- match: ':'
push:
- meta_scope: meta.format-spec.python constant.other.format-spec.python
Expand All @@ -1438,7 +1447,7 @@ contexts:
- match: ''
push:
- meta_content_scope: source.python.embedded
- match: (?=![^=]|:|\})
- match: (?==?(![^=]|:|\}))
pop: true
- match: \\
scope: invalid.illegal.backslash-in-fstring.python
Expand Down
9 changes: 9 additions & 0 deletions Python/syntax_test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,15 @@ def foo(arg: int = 0, (x: float, y=20) = (0.0, "default")):
# ^ punctuation.section.sequence.end.python
pass
def name(p1, p2=None, /, p_or_kw=None, *, kw): pass
# ^ storage.modifier.positional-args-only.python
# ^ punctuation.separator.parameters.python
# ^ keyword.operator.unpacking.sequence.python
def name(p1, p2, /): pass
# ^ storage.modifier.positional-args-only.python
# ^ punctuation.section.parameters.end.python
##################
# Class definitions
##################
Expand Down
27 changes: 27 additions & 0 deletions Python/syntax_test_python_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,33 @@
# ^ invalid.illegal.stray-brace
"""

# Most of these were inspired by
# https://github.com/python/cpython/commit/9a4135e939bc223f592045a38e0f927ba170da32
f'{x=:}'
# ^ storage.modifier.debug.python
f'{x=:.2f}'
# ^ storage.modifier.debug.python
f'{x=!r}'
# ^ storage.modifier.debug.python
f'{x=!a}'
# ^ storage.modifier.debug.python
f'{x=!s:*^20}'
# ^ storage.modifier.debug.python
# ^^ storage.modifier.conversion.python
# ^^^^^ meta.format-spec.python
f'{"Σ"=}'
# ^ storage.modifier.debug.python
f'{0==1}'
# ^^ -storage.modifier.debug.python
f'{0!=1}'
# ^ -storage.modifier.debug.python
f'{0<=1}'
# ^ -storage.modifier.debug.python
f'{0>=1}'
# ^ -storage.modifier.debug.python
f'{f(a="3=")}'
# ^^^^ -storage.modifier.debug.python

f" {
% ^ invalid.illegal.unclosed-string
# TODO make this test pass
Expand Down

0 comments on commit bb649b0

Please sign in to comment.