Skip to content

Commit

Permalink
Restructure get_keyword_argument and get_argument_from_call in a try …
Browse files Browse the repository at this point in the history
…except block and Make support for negative indices proper

#38
  • Loading branch information
mpourmpoulis committed Aug 22, 2020
1 parent 0e1fd16 commit 3146c04
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions library/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,21 +473,32 @@ def get_exception_handler(root,atok):

def get_positional_argument(root,index = None):
temporary = root.args if match_node(root,(ast.Call )) else None
return (
(temporary[index] if index and len(temporary)>index else temporary)
if temporary else None
)
if temporary:
try :
return temporary[index]
except (IndexError,TypeError):
return temporary
# return (
# (temporary[index] if index and len(temporary)>index else temporary)
# if temporary else None
# )

def get_keyword_argument(root,index = None,only_value = True,only_keyword = False):
temporary = root.keywords if match_node(root,(ast.Call )) else None
if only_value and not only_keyword:
temporary = [x.value for x in temporary] if temporary else None
elif only_keyword:
temporary = [get_fake(x,"arg") for x in temporary if generic_fix(x,None)] if temporary else None
return (
(temporary[index] if index is not None and len(temporary)>index else temporary)
if temporary else None
)
if temporary:
try :
return temporary[index]
except (IndexError,TypeError):
return temporary

# return (
# (temporary[index] if index is not None and len(temporary)>index else temporary)
# if temporary else None
# )

def get_star_argument(root,index = None):
temporary = root.starargs if match_node(root,(ast.Call )) else None
Expand Down Expand Up @@ -516,8 +527,11 @@ def get_argument_from_call(root, index):
temporary = make_flat([x for x in temporary if x])
temporary = [x for x in temporary if x]
temporary = sorted(temporary,key= lambda x:x.first_token.startpos)
# print(" I would regret face", temporary)
return temporary[index] if temporary and len(temporary)>index else None
try :
return temporary[index]
except :
return None
# return temporary[index] if temporary and len(temporary)>index else None



Expand Down

0 comments on commit 3146c04

Please sign in to comment.