Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Python TSG: Error when a lambda does not have a parameter list #440

@ghost

Description

When a Python lambda does not have an parameter list, the current TSG fails.

Example

The rules currently fail for the following CST.

(lambda [207, 32] - [207, 69]
  body: (call [207, 40] - [207, 69]
    function: (attribute [207, 40] - [207, 53]
      object: (identifier [207, 40] - [207, 48])
      attribute: (identifier [207, 49] - [207, 53]))
    arguments: (argument_list [207, 53] - [207, 69]
      (list_splat [207, 54] - [207, 68]
        (attribute [207, 55] - [207, 68]
          object: (identifier [207, 55] - [207, 63])
          attribute: (identifier [207, 64] - [207, 68]))))))))))))))

Suggested change

[
  (function_definition
--    parameters: (_) @params
++    parameters: (_)? @params
    body: (_) @body
  ) @func
  (lambda
--    parameters: (_) @params
++    parameters: (_)? @params
    body: (_) @body
  )@func
] {
  node @func.call
  node return_value
  node drop_scope

  edge @func.call -> return_value

++  if some @params {
    edge @body.before_scope -> @params.after_scope
++  }
  edge @body.before_scope -> drop_scope
  edge drop_scope -> @func.bottom
  attr (drop_scope) type = "drop_scopes"
  attr (@func.call) pop_scoped_symbol = "()"
++  if some @params {
    edge @params.before_scope -> JUMP_TO_SCOPE_NODE
++  }
  attr (return_value) is_exported
  let @func.function_returns = return_value
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions