-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python Highlighting - type
is matched too aggressively as a keyword
#3902
Comments
Despite As a result it used to be highlighted comparable prominent various color schemes, before. With a restriction applied to Mariana: Monokai Brackets |
Scoping it as As for whether or not we should scope the target of assigmnets as class A:
type = 'a'
other = type
# vs
class B:
other = type Also, because Python is a language with significant whitespace (indentation) that is infeasible to determine and track with syntax definitions, there is no point in trying to make a special exception for when |
Both scopes are sub-optimal and I rather tend to also dislike scoping builtin-function-identifiers special in non-function-call expressions. Shadowing existing globals is not a syntax error or disallowed in any way and fully within responsibility of the author. |
Fixes sublimehq#3902 This commit ensures to highlight `type` more context sensitively. It may have the following meanings: 1. built-in `type()` function 2. type alias declaration keyword: `type Alias` 3. ordinary variable used in many data classes The built-in function (1.) most likely appears in r-value expressions, such as `my_type = type(var)` At beginning of statements this commit prefers scoping `type` as keyword (2.) or variable (3.) as this is the most likely use case. The implementation ensures to start `meta` scope of alias declarations at bol as class or function declarations do.
Fixes sublimehq#3902 This commit ensures to highlight `type` more context sensitively. It may have the following meanings: 1. built-in `type()` function 2. type alias declaration keyword: `type Alias` 3. ordinary variable used in many data classes The built-in function (1.) most likely appears in r-value expressions, such as `my_type = type(var)` At beginning of statements this commit prefers scoping `type` as keyword (2.) or variable (3.) as this is the most likely use case. The implementation ensures to start `meta` scope of alias declarations at bol as class or function declarations do.
Fixes sublimehq#3902 This commit ensures to highlight `type` more context sensitively. It may have the following meanings: 1. built-in `type()` function 2. type alias declaration keyword: `type Alias` 3. ordinary variable used in many data classes The built-in function (1.) most likely appears in r-value expressions, such as `my_type = type(var)` At beginning of statements this commit prefers scoping `type` as keyword (2.) or variable (3.) as this is the most likely use case. The implementation ensures to start `meta` scope of alias declarations at bol as class or function declarations do.
Fixes #3902 This commit ensures to highlight `type` more context sensitively. It may have the following meanings: 1. built-in `type()` function 2. type alias declaration keyword: `type Alias` 3. ordinary variable used in many data classes The built-in function (1.) most likely appears in r-value expressions, such as `my_type = type(var)` At beginning of statements this commit prefers scoping `type` as keyword (2.) or variable (3.) as this is the most likely use case. The implementation ensures to start `meta` scope of alias declarations at bol as class or function declarations do.
Description of the bug
I noticed that recently, Sublime started highlighting
type
as a keyword, but this causes some issues because it is officially only a soft keyword that also happens to share a name with a builtin function. Depending on context,type
could be a keyword or an identifier, and this has some minor rippling effects on later highlights in the line (and sometimes spilling onto later lines)Steps to reproduce
Observe the weird highlighting that acts as if
type
is a keyword here even though it isn'tExpected behavior
The official grammar for type statements is as follows:
Therefore I propose that
type
should only be highlighted as a keyword in the following situations:As soon as
type
is followed by anything other than an identifier, it should revert to being highlighted as a builtin or identifier. (Ideally it should be highlighted as a regular identifier when it is on the left side of an assignment or type annotation, but being highlighted as a builtin (as it was before) didn't cause any cascading issues with syntax highlighting and is tolerable)Actual behavior
Currently, it appears that
type
is treated as a keyword when it is the first token on a line, regardless of what tokens follow it on that line.Sublime Text build number
4169
Operating system & version
MacOS Sonoma 14.1.1
(Linux) Desktop environment and/or window manager
No response
Additional information
No response
OpenGL context information
No response
The text was updated successfully, but these errors were encountered: