mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
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:
@@ -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(','),
|
||||
']'
|
||||
)),
|
||||
|
||||
Reference in New Issue
Block a user