@@ -50,7 +50,7 @@ def handle_keywords(self, func, node, offset=0):
5050 defaults = func .args .defaults
5151 keywords = {func_argument_names [kw .arg ]: kw .value
5252 for kw in node .keywords }
53- node .args .extend ([None ] * (1 + max ( keywords . keys ()) - len (node .args )))
53+ node .args .extend ([None ] * (nargs - len (node .args )))
5454
5555 replacements = {}
5656 for index , arg in enumerate (node .args ):
@@ -59,45 +59,45 @@ def handle_keywords(self, func, node, offset=0):
5959 replacements [index ] = deepcopy (keywords [index ])
6060 else : # must be a default value
6161 replacements [index ] = deepcopy (defaults [index - nargs ])
62+
6263 return replacements
6364
6465 def visit_Call (self , node ):
65- if node .keywords :
66- self .update = True
67-
68- aliases = self .aliases [node .func ]
69- assert aliases , "at least one alias"
70-
71- # all aliases should have the same structural type...
72- # call to self.handle_keywords raises an exception otherwise
73- try :
74- replacements = {}
75- for func_alias in aliases :
76- handle_special_calls (func_alias , node )
77-
78- if func_alias is None : # aliasing computation failed
79- pass
80- elif isinstance (func_alias , ast .Call ): # nested function
81- # func_alias looks like functools.partial(foo, a)
82- # so we reorder using alias for 'foo'
83- offset = len (func_alias .args ) - 1
84- call = func_alias .args [0 ]
85- for func_alias in self .aliases [call ]:
86- replacements = self .handle_keywords (func_alias ,
87- node , offset )
88- else :
89- replacements = self .handle_keywords (func_alias , node )
90-
91- # if we reach this point, we should have a replacement
92- # candidate, or nothing structural typing issues would have
93- # raised an exception in handle_keywords
94- if replacements :
95- for index , value in replacements .items ():
96- node .args [index ] = value
97- node .keywords = []
98-
99- except KeyError as ve :
100- err = ("function uses an unknown (or unsupported) keyword "
101- "argument `{}`" .format (ve .args [0 ]))
102- raise PythranSyntaxError (err , node )
66+ self .update = True
67+
68+ aliases = self .aliases [node .func ]
69+ assert aliases , "at least one alias"
70+
71+ # all aliases should have the same structural type...
72+ # call to self.handle_keywords raises an exception otherwise
73+ try :
74+ replacements = {}
75+ for func_alias in aliases :
76+ handle_special_calls (func_alias , node )
77+
78+ if func_alias is None : # aliasing computation failed
79+ pass
80+ elif isinstance (func_alias , ast .Call ): # nested function
81+ # func_alias looks like functools.partial(foo, a)
82+ # so we reorder using alias for 'foo'
83+ offset = len (func_alias .args ) - 1
84+ call = func_alias .args [0 ]
85+ for func_alias in self .aliases [call ]:
86+ replacements = self .handle_keywords (func_alias ,
87+ node , offset )
88+ else :
89+ replacements = self .handle_keywords (func_alias , node )
90+
91+ # if we reach this point, we should have a replacement
92+ # candidate, or nothing structural typing issues would have
93+ # raised an exception in handle_keywords
94+ if replacements :
95+ for index , value in replacements .items ():
96+ node .args [index ] = value
97+ node .keywords = []
98+
99+ except KeyError as ve :
100+ err = ("function uses an unknown (or unsupported) keyword "
101+ "argument `{}`" .format (ve .args [0 ]))
102+ raise PythranSyntaxError (err , node )
103103 return self .generic_visit (node )
0 commit comments