Skip to content
New issue

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

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

Already on GitHub? # to your account

Difference in fields between parameters #199

Open
Qwarctick opened this issue Feb 21, 2023 · 2 comments
Open

Difference in fields between parameters #199

Qwarctick opened this issue Feb 21, 2023 · 2 comments

Comments

@Qwarctick
Copy link

If I have this code:

def func(first, second: str, third = 7, four: int = 1):
    print()

I got the following abstract tree:

module [0, 0] - [2, 0]
  function_definition [0, 0] - [1, 11]
    name: identifier [0, 4] - [0, 8]
    parameters: parameters [0, 8] - [0, 54]
      identifier [0, 9] - [0, 14]
      typed_parameter [0, 16] - [0, 27]
        identifier [0, 16] - [0, 22]
        type: type [0, 24] - [0, 27]
          identifier [0, 24] - [0, 27]
      default_parameter [0, 29] - [0, 38]
        name: identifier [0, 29] - [0, 34]
        value: integer [0, 37] - [0, 38]
      typed_default_parameter [0, 40] - [0, 53]
        name: identifier [0, 40] - [0, 44]
        type: type [0, 46] - [0, 49]
          identifier [0, 46] - [0, 49]
        value: integer [0, 52] - [0, 53]
    body: block [1, 4] - [1, 11]
      expression_statement [1, 4] - [1, 11]
        call [1, 4] - [1, 11]
          function: identifier [1, 4] - [1, 9]
          arguments: argument_list [1, 9] - [1, 11]

My question is: Why is the first parameter and typed_parameter does not have a name field like default_parameter and typed_default_parameter.
Or in the other way, why default_parameter and typed_default_parameter need a name field ?

Is there any reason to this design ?

Maybe it's possible to homogenize all this.

@amaanq
Copy link
Member

amaanq commented Jul 22, 2023

My guess is typed_parameter can have list/dict splat patterns, hence it's not always a name, though I'm not against adding a name field

@almahdi404
Copy link

Using identifier is very confusing while doing program logic.

It would be better to parse it like this

parameters: parameters [0, 8] - [0, 54]
  parameter: [0, 9] - [0, 14]
    name: identifier [0, 9] - [0, 14]

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants