Skip to content

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Apr 1, 2020

Copy link
Member

@isidentical isidentical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This position information is wrong on **kwargs

>>> source = "class X(**kwarg): pass"
>>> node = ast.parse(source).body[0].keywords[0]
>>> ast.get_source_segment(source, node)
'**'
>>> source = "a(**kwarg)"
>>> node = ast.parse(source).body[0].value.keywords[0]
>>> ast.get_source_segment(source, node)
'**'

@isidentical isidentical added the type-feature A feature request or enhancement label Apr 1, 2020
@pablogsal
Copy link
Member Author

pablogsal commented Apr 1, 2020

This position information is wrong on **kwargs

Hummm, I don't think so, the name for the "kwargs" is in the value:

f = 'f(x,y,z,**idfsjoidjfgiodfg)'
ss = ast.parse(f).body[0].value.keywords[0]
>>> f[ss.value.col_offset:ss.value.end_col_offset]
'idfsjoidjfgiodfg'

Edit: I checked and seems that args is behaving like what you propose

>>> f
'f(x,*dsfsdf,z,k=34,**idfsjoidjfgiodfg)'
>>> x = ast.parse(f).body[0].value
>>> l = x.args[1]      
>>> f[l.col_offset:l.end_col_offset]
'*dsfsdf'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants