Hi!
I tried the following code to parse import statements :
source = 'import asttokens as at'
atok = asttokens.ASTTokens(source, parse=True)
I get the following AST:
Which is OK. My purpose is to gather the position of the identifiers asttokens and at in the code. Therefore I was trying to get the tokens composing the alias node, which sounds logic because asttokens as at is and alias definition. However when I ask for the tokens composing the alias node, using list(atok.get_tokens(atok.tree.body[0].names[0])) I get the following result :
[Token(type=1, string=u'import', start=(1, 0), end=(1, 6), line=u'import asttokens as at', index=0, startpos=0, endpos=6)]
Which is was not what I was expecting, I was expecting to have the ['asttokens', 'as', 'at'] tokens.
Is there something I am missing?
Best regards.
Hi!
I tried the following code to parse import statements :
I get the following AST:
Which is OK. My purpose is to gather the position of the identifiers
asttokensandatin the code. Therefore I was trying to get the tokens composing the alias node, which sounds logic becauseasttokens as atis and alias definition. However when I ask for the tokens composing the alias node, usinglist(atok.get_tokens(atok.tree.body[0].names[0]))I get the following result :Which is was not what I was expecting, I was expecting to have the
['asttokens', 'as', 'at']tokens.Is there something I am missing?
Best regards.