@@ -39,6 +39,9 @@ repository:
39
39
{
40
40
include : " #import"
41
41
}
42
+ {
43
+ include : " #type-declaration"
44
+ }
42
45
{
43
46
include : " #class-declaration"
44
47
}
@@ -1099,6 +1102,45 @@ repository:
1099
1102
]
1100
1103
}
1101
1104
]
1105
+ " type-declaration" :
1106
+ name : " meta.type.python"
1107
+ begin : '''
1108
+ (?x)
1109
+ \\ s*(type)\\ s+
1110
+ (?=
1111
+ [[:alpha:]_][[:word:]]* \\ s* [=\\ []
1112
+ )
1113
+
1114
+ '''
1115
+ end : " ((?=[=]))"
1116
+ beginCaptures :
1117
+ " 1" :
1118
+ name : " storage.type.type.python"
1119
+ patterns : [
1120
+ {
1121
+ include : " #type-name"
1122
+ }
1123
+ {
1124
+ include : " #type-parameters"
1125
+ }
1126
+ ]
1127
+ " type-name" :
1128
+ patterns : [
1129
+ {
1130
+ include : " #illegal-object-name"
1131
+ }
1132
+ {
1133
+ include : " #builtin-possible-callables"
1134
+ }
1135
+ {
1136
+ name : " entity.name.type.type.python"
1137
+ match : '''
1138
+ (?x)
1139
+ \\ b ([[:alpha:]_]\\ w*) \\ b
1140
+
1141
+ '''
1142
+ }
1143
+ ]
1102
1144
" class-declaration" :
1103
1145
patterns : [
1104
1146
{
@@ -1107,7 +1149,7 @@ repository:
1107
1149
(?x)
1108
1150
\\ s*(class)\\ s+
1109
1151
(?=
1110
- [[:alpha:]_]\\ w* \\ s* (:|\\ ( )
1152
+ [[:alpha:]_]\\ w* \\ s* (:|[ \\ [(] )
1111
1153
)
1112
1154
1113
1155
'''
@@ -1125,6 +1167,9 @@ repository:
1125
1167
{
1126
1168
include : " #class-inheritance"
1127
1169
}
1170
+ {
1171
+ include : " #type-parameters"
1172
+ }
1128
1173
]
1129
1174
}
1130
1175
]
@@ -1355,7 +1400,7 @@ repository:
1355
1400
\\ s*
1356
1401
(?:\\ b(async) \\ s+)? \\ b(def)\\ s+
1357
1402
(?=
1358
- [[:alpha:]_][[:word:]]* \\ s* \\ (
1403
+ [[:alpha:]_][[:word:]]* \\ s* [( \\ []
1359
1404
)
1360
1405
1361
1406
'''
@@ -1372,6 +1417,9 @@ repository:
1372
1417
{
1373
1418
include : " #function-def-name"
1374
1419
}
1420
+ {
1421
+ include : " #type-parameters"
1422
+ }
1375
1423
{
1376
1424
include : " #parameters"
1377
1425
}
@@ -1399,6 +1447,67 @@ repository:
1399
1447
'''
1400
1448
}
1401
1449
]
1450
+ " type-parameters" :
1451
+ name : " meta.function.parameters.type.python"
1452
+ begin : " (\\ [)"
1453
+ end : " (\\ ])"
1454
+ beginCaptures :
1455
+ " 1" :
1456
+ name : " punctuation.definition.parameters.begin.python"
1457
+ endCaptures :
1458
+ " 1" :
1459
+ name : " punctuation.definition.parameters.end.python"
1460
+ patterns : [
1461
+ {
1462
+ name : " keyword.operator.unpacking.parameter.python"
1463
+ match : " (\\ *\\ *|\\ *)"
1464
+ }
1465
+ {
1466
+ include : " #lambda-incomplete"
1467
+ }
1468
+ {
1469
+ include : " #illegal-names"
1470
+ }
1471
+ {
1472
+ include : " #illegal-object-name"
1473
+ }
1474
+ {
1475
+ match : '''
1476
+ (?x)
1477
+ ([[:alpha:]_]\\ w*)
1478
+ \\ s* (?: (,) | (?=[\\ ]#\\ n=]))
1479
+
1480
+ '''
1481
+ captures :
1482
+ " 1" :
1483
+ name : " variable.parameter.function.language.python"
1484
+ " 2" :
1485
+ name : " punctuation.separator.parameters.python"
1486
+ }
1487
+ {
1488
+ include : " #comments"
1489
+ }
1490
+ {
1491
+ include : " #type-loose-default"
1492
+ }
1493
+ {
1494
+ include : " #type-annotated-parameter"
1495
+ }
1496
+ ]
1497
+ " type-loose-default" :
1498
+ begin : " (=)"
1499
+ end : " (,)|(?=\\ ])"
1500
+ beginCaptures :
1501
+ " 1" :
1502
+ name : " keyword.operator.python"
1503
+ endCaptures :
1504
+ " 1" :
1505
+ name : " punctuation.separator.parameters.python"
1506
+ patterns : [
1507
+ {
1508
+ include : " #expression"
1509
+ }
1510
+ ]
1402
1511
parameters :
1403
1512
name : " meta.function.parameters.python"
1404
1513
begin : " (\\ ()"
@@ -1482,6 +1591,31 @@ repository:
1482
1591
include : " #expression"
1483
1592
}
1484
1593
]
1594
+ " type-annotated-parameter" :
1595
+ begin : '''
1596
+ (?x)
1597
+ \\ b
1598
+ ([[:alpha:]_]\\ w*) \\ s* (:)
1599
+
1600
+ '''
1601
+ end : " (,)|(?=\\ ])"
1602
+ beginCaptures :
1603
+ " 1" :
1604
+ name : " variable.parameter.function.language.python"
1605
+ " 2" :
1606
+ name : " punctuation.separator.annotation.python"
1607
+ endCaptures :
1608
+ " 1" :
1609
+ name : " punctuation.separator.parameters.python"
1610
+ patterns : [
1611
+ {
1612
+ include : " #expression"
1613
+ }
1614
+ {
1615
+ name : " keyword.operator.assignment.python"
1616
+ match : " =(?!=)"
1617
+ }
1618
+ ]
1485
1619
" annotated-parameter" :
1486
1620
begin : '''
1487
1621
(?x)
0 commit comments