@@ -142,6 +142,7 @@ repository:
142142 statement :
143143 patterns :
144144 - include : ' #import'
145+ - include : ' #type-declaration'
145146 - include : ' #class-declaration'
146147 - include : ' #function-declaration'
147148 - include : ' #generator'
@@ -831,14 +832,39 @@ repository:
831832 match : \b(?<!\.)as\b
832833 - include : ' #expression'
833834
835+ type-declaration :
836+ name : meta.type.python
837+ begin : |
838+ (?x)
839+ \s*(type)\s+
840+ (?=
841+ [[:alpha:]_][[:word:]]* \s* [=\[]
842+ )
843+
844+ end : ((?=[=]))
845+ beginCaptures :
846+ ' 1 ' : {name: storage.type.type.python}
847+ patterns :
848+ - include : ' #type-name'
849+ - include : ' #type-parameters'
850+
851+ type-name :
852+ patterns :
853+ - include : ' #illegal-object-name'
854+ - include : ' #builtin-possible-callables'
855+ - name : entity.name.type.type.python
856+ match : |
857+ (?x)
858+ \b ([[:alpha:]_]\w*) \b
859+
834860 class-declaration :
835861 patterns :
836862 - name : meta.class.python
837863 begin : |
838864 (?x)
839865 \s*(class)\s+
840866 (?=
841- [[:alpha:]_]\w* \s* (:|\( )
867+ [[:alpha:]_]\w* \s* (:|[\[(] )
842868 )
843869 end : (:)
844870 beginCaptures :
@@ -848,6 +874,7 @@ repository:
848874 patterns :
849875 - include : ' #class-name'
850876 - include : ' #class-inheritance'
877+ - include : ' #type-parameters'
851878
852879 class-name :
853880 patterns :
@@ -992,7 +1019,7 @@ repository:
9921019 \s*
9931020 (?:\b(async) \s+)? \b(def)\s+
9941021 (?=
995- [[:alpha:]_][[:word:]]* \s* \(
1022+ [[:alpha:]_][[:word:]]* \s* [(\[]
9961023 )
9971024
9981025 end : (:|(?=[#'"\n]))
@@ -1005,6 +1032,7 @@ repository:
10051032
10061033 patterns :
10071034 - include : ' #function-def-name'
1035+ - include : ' #type-parameters'
10081036 - include : ' #parameters'
10091037 - include : ' #line-continuation'
10101038 - include : ' #return-annotation'
@@ -1018,6 +1046,43 @@ repository:
10181046 (?x)
10191047 \b ([[:alpha:]_]\w*) \b
10201048
1049+ type-parameters :
1050+ name : meta.function.parameters.type.python
1051+ begin : (\[)
1052+ end : (\])
1053+ beginCaptures :
1054+ ' 1 ' : {name: punctuation.definition.parameters.begin.python}
1055+ endCaptures :
1056+ ' 1 ' : {name: punctuation.definition.parameters.end.python}
1057+
1058+ patterns :
1059+ - name : keyword.operator.unpacking.parameter.python
1060+ match : (\*\*|\*)
1061+ - include : ' #lambda-incomplete'
1062+ - include : ' #illegal-names'
1063+ - include : ' #illegal-object-name'
1064+ - match : |
1065+ (?x)
1066+ ([[:alpha:]_]\w*)
1067+ \s* (?: (,) | (?=[\]#\n=]))
1068+ captures:
1069+ '1': {name: variable.parameter.function.language.python}
1070+ '2': {name: punctuation.separator.parameters.python}
1071+
1072+ - include : ' #comments'
1073+ - include : ' #type-loose-default'
1074+ - include : ' #type-annotated-parameter'
1075+
1076+ type-loose-default :
1077+ begin : (=)
1078+ end : (,)|(?=\])
1079+ beginCaptures :
1080+ ' 1 ' : {name: keyword.operator.python}
1081+ endCaptures :
1082+ ' 1 ' : {name: punctuation.separator.parameters.python}
1083+ patterns :
1084+ - include : ' #expression'
1085+
10211086 parameters :
10221087 name : meta.function.parameters.python
10231088 begin : (\()
@@ -1068,6 +1133,22 @@ repository:
10681133 patterns :
10691134 - include : ' #expression'
10701135
1136+ type-annotated-parameter :
1137+ begin : |
1138+ (?x)
1139+ \b
1140+ ([[:alpha:]_]\w*) \s* (:)
1141+ end : (,)|(?=\])
1142+ beginCaptures :
1143+ ' 1 ' : {name: variable.parameter.function.language.python}
1144+ ' 2 ' : {name: punctuation.separator.annotation.python}
1145+ endCaptures :
1146+ ' 1 ' : {name: punctuation.separator.parameters.python}
1147+ patterns :
1148+ - include : ' #expression'
1149+ - name : keyword.operator.assignment.python
1150+ match : =(?!=)
1151+
10711152 annotated-parameter :
10721153 begin : |
10731154 (?x)
0 commit comments