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.
This commit is contained in:
Taus
2024-10-08 12:25:13 +00:00
parent 1ced5b44d7
commit 882249ef82

View File

@@ -589,17 +589,20 @@ module.exports = grammar({
typevar_parameter: $ => seq(
field('name', $.identifier),
optional($._type_bound)
optional($._type_bound),
optional($._type_param_default)
),
typevartuple_parameter: $ => seq(
'*',
field('name', $.identifier),
optional($._type_param_default)
),
paramspec_parameter: $ => seq(
'**',
field('name', $.identifier),
optional($._type_param_default),
),
_type_parameter: $ => choice(
@@ -608,6 +611,11 @@ module.exports = grammar({
$.paramspec_parameter,
),
_type_param_default: $ => seq(
'=',
field('default', choice($.list_splat, $.expression))
),
parenthesized_list_splat: $ => prec(PREC.parenthesized_list_splat, seq(
'(',
choice(
@@ -923,7 +931,7 @@ module.exports = grammar({
subscript: $ => prec(PREC.call, seq(
field('value', $.primary_expression),
'[',
commaSep1(field('subscript', choice($.expression, $.slice))),
commaSep1(field('subscript', choice($.list_splat, $.expression, $.slice))),
optional(','),
']'
)),