Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python TSG: Unable to parse lambda in parameter/arguments #403

Closed
SubhamPramanik opened this issue Feb 22, 2024 · 3 comments · Fixed by #426
Closed

Python TSG: Unable to parse lambda in parameter/arguments #403

SubhamPramanik opened this issue Feb 22, 2024 · 3 comments · Fixed by #426

Comments

@SubhamPramanik
Copy link

Python Code:

for tag in soup.find_all(href=lambda x: x and x.startswith("data:")):
on_backoff=lambda details: print(
update_available = check_version(lambda msg: None)
ranked_definitions = sorted(ranked_definitions.items(), reverse=True, key=lambda x: x[1])
directories.sort(key=lambda dname: pass_counts[dname], reverse=True)

Failing Stanza:

(parameter/identifier) @param @name
{
  attr (@name.def) node_definition = @name
  attr (@param.param_name) push_node = @param
  edge @name.def -> @param.param_name
  edge @name.def -> @param.param_index
  edge @param.input -> @name.def
}
@ghost
Copy link

ghost commented Feb 27, 2024

A more minimalistic example

Input

sorted([1, 2, 3], key=lambda x: x)

CST

(module [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 34]
    (call [0, 0] - [0, 34]
      function: (identifier [0, 0] - [0, 6])
      arguments: (argument_list [0, 6] - [0, 34]
        (list [0, 7] - [0, 16]
          (integer [0, 8] - [0, 9])
          (integer [0, 11] - [0, 12])
          (integer [0, 14] - [0, 15]))
        (keyword_argument [0, 18] - [0, 33]
          name: (identifier [0, 18] - [0, 21])
          value: (lambda [0, 22] - [0, 33]
            parameters: (lambda_parameters [0, 29] - [0, 30]
              (identifier [0, 29] - [0, 30]))
            body: (identifier [0, 32] - [0, 33])))))))

Suggested fix

++[
  (parameters
    (_) @param) @params
++  (lambda_parameters
++    (_) @param) @params
-- {
++] {
  node @param.param_index
  node @param.param_name

  attr (@param.param_index) push_symbol = (named-child-index @param)
  edge @param.param_index -> @params.before_scope
  edge @params.after_scope -> @param.input
  edge @param.param_name -> @params.before_scope
}

@hendrikvanantwerpen
Copy link
Collaborator

Thanks for reporting these and other issues! If it's possible to create PRs for issues where you have suggested fixes, that will make it easier for me to get them in with the limited time I currently have for this project.

@berrazuriz1
Copy link

Did the issue got resolved? I'm getting the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants