1
+ import functools
1
2
import inspect
2
3
import textwrap
3
4
@@ -24,7 +25,7 @@ def concatenate_functions(
24
25
Functions that are not required to produce the targets will simply be ignored.
25
26
26
27
The arguments of the combined function are all arguments of relevant functions
27
- that are not themselves function names.
28
+ that are not themselves function names, in alphabetical order .
28
29
29
30
Args:
30
31
functions (dict or list): Dict or list of functions. If a list, the function
@@ -152,14 +153,22 @@ def _create_complete_dag(functions):
152
153
153
154
"""
154
155
functions_arguments_dict = {
155
- name : list (inspect .signature (function ).parameters )
156
- for name , function in functions .items ()
156
+ name : _get_free_arguments (function ) for name , function in functions .items ()
157
157
}
158
158
dag = nx .DiGraph (functions_arguments_dict ).reverse ()
159
159
160
160
return dag
161
161
162
162
163
+ def _get_free_arguments (func ):
164
+ arguments = list (inspect .signature (func ).parameters )
165
+ if isinstance (func , functools .partial ):
166
+ non_free = set (func .args ) | set (func .keywords )
167
+ arguments = [arg for arg in arguments if arg not in non_free ]
168
+
169
+ return arguments
170
+
171
+
163
172
def _limit_dag_to_targets_and_their_ancestors (dag , targets ):
164
173
"""Limit DAG to targets and their ancestors.
165
174
@@ -216,7 +225,7 @@ def _create_execution_info(functions, dag):
216
225
out = {}
217
226
for node in nx .topological_sort (dag ):
218
227
if node in functions :
219
- arguments = list ( inspect . signature ( functions [node ]). parameters )
228
+ arguments = _get_free_arguments ( functions [node ])
220
229
info = {}
221
230
info ["func" ] = functions [node ]
222
231
info ["arguments" ] = arguments
0 commit comments