Skip to content
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] Improve type alias definitions #3917

Merged

Conversation

deathaxe
Copy link
Collaborator

@deathaxe deathaxe commented Feb 3, 2024

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.

@deathaxe deathaxe force-pushed the pr/python/fix-type-alias-definitions branch from b1c1ccc to 582c45b Compare February 3, 2024 10:50
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.
@deathaxe deathaxe force-pushed the pr/python/fix-type-alias-definitions branch from 582c45b to df98fff Compare February 3, 2024 10:52
@deathaxe deathaxe merged commit 350e338 into sublimehq:master Feb 3, 2024
2 checks passed
@deathaxe deathaxe deleted the pr/python/fix-type-alias-definitions branch February 3, 2024 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python Highlighting - type is matched too aggressively as a keyword
3 participants