Skip to content

Commit 882249e

Browse files
committed
Python: Add grammar support for type defaults
Also fixes an oversight in the grammar: starred expressions should be allowed inside the subscript of an `Index` expression.
1 parent 1ced5b4 commit 882249e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

python/extractor/tsg-python/tsp/grammar.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,17 +589,20 @@ module.exports = grammar({
589589

590590
typevar_parameter: $ => seq(
591591
field('name', $.identifier),
592-
optional($._type_bound)
592+
optional($._type_bound),
593+
optional($._type_param_default)
593594
),
594595

595596
typevartuple_parameter: $ => seq(
596597
'*',
597598
field('name', $.identifier),
599+
optional($._type_param_default)
598600
),
599601

600602
paramspec_parameter: $ => seq(
601603
'**',
602604
field('name', $.identifier),
605+
optional($._type_param_default),
603606
),
604607

605608
_type_parameter: $ => choice(
@@ -608,6 +611,11 @@ module.exports = grammar({
608611
$.paramspec_parameter,
609612
),
610613

614+
_type_param_default: $ => seq(
615+
'=',
616+
field('default', choice($.list_splat, $.expression))
617+
),
618+
611619
parenthesized_list_splat: $ => prec(PREC.parenthesized_list_splat, seq(
612620
'(',
613621
choice(
@@ -923,7 +931,7 @@ module.exports = grammar({
923931
subscript: $ => prec(PREC.call, seq(
924932
field('value', $.primary_expression),
925933
'[',
926-
commaSep1(field('subscript', choice($.expression, $.slice))),
934+
commaSep1(field('subscript', choice($.list_splat, $.expression, $.slice))),
927935
optional(','),
928936
']'
929937
)),

0 commit comments

Comments
 (0)