@@ -52,17 +52,20 @@ def _save_as_to_mapping(save_as):
5252 # NOTE(harlowja): this means that your atom will return a indexable
5353 # object, like a list or tuple and the results can be mapped by index
5454 # to that tuple/list that is returned for others to use.
55- return collections .OrderedDict ((key , num )
56- for num , key in enumerate (save_as ))
55+ return collections .OrderedDict (
56+ (key , num ) for num , key in enumerate (save_as )
57+ )
5758 elif isinstance (save_as , _set_types ):
5859 # NOTE(harlowja): in the case where a set is given we will not be
5960 # able to determine the numeric ordering in a reliable way (since it
6061 # may be an unordered set) so the only way for us to easily map the
6162 # result of the atom will be via the key itself.
6263 return collections .OrderedDict ((key , key ) for key in save_as )
6364 else :
64- raise TypeError ('Atom provides parameter '
65- 'should be str, set or tuple/list, not %r' % save_as )
65+ raise TypeError (
66+ 'Atom provides parameter '
67+ 'should be str, set or tuple/list, not %r' % save_as
68+ )
6669
6770
6871def _build_rebind_dict (req_args , rebind_args ):
@@ -84,17 +87,19 @@ def _build_rebind_dict(req_args, rebind_args):
8487 # Extra things were rebound, that may be because of *args
8588 # or **kwargs (or some other reason); so just keep all of them
8689 # using 1:1 rebinding...
87- rebind .update ((a , a ) for a in rebind_args [len (req_args ):])
90+ rebind .update ((a , a ) for a in rebind_args [len (req_args ) :])
8891 return rebind
8992 elif isinstance (rebind_args , dict ):
9093 return rebind_args
9194 else :
92- raise TypeError ("Invalid rebind value '%s' (%s)"
93- % (rebind_args , type (rebind_args )))
95+ raise TypeError (
96+ "Invalid rebind value '%s' (%s)" % (rebind_args , type (rebind_args ))
97+ )
9498
9599
96- def _build_arg_mapping (atom_name , reqs , rebind_args , function , do_infer ,
97- ignore_list = None ):
100+ def _build_arg_mapping (
101+ atom_name , reqs , rebind_args , function , do_infer , ignore_list = None
102+ ):
98103 """Builds an input argument mapping for a given function.
99104
100105 Given a function, its requirements and a rebind mapping this helper
@@ -135,8 +140,9 @@ def _build_arg_mapping(atom_name, reqs, rebind_args, function, do_infer,
135140 # Determine if there are optional arguments that we may or may not take.
136141 if do_infer :
137142 opt_args = sets .OrderedSet (all_args )
138- opt_args = opt_args - set (itertools .chain (required .keys (),
139- iter (ignore_list )))
143+ opt_args = opt_args - set (
144+ itertools .chain (required .keys (), iter (ignore_list ))
145+ )
140146 optional = collections .OrderedDict ((a , a ) for a in opt_args )
141147 else :
142148 optional = collections .OrderedDict ()
@@ -146,14 +152,17 @@ def _build_arg_mapping(atom_name, reqs, rebind_args, function, do_infer,
146152 extra_args = sets .OrderedSet (required .keys ())
147153 extra_args -= all_args
148154 if extra_args :
149- raise ValueError ('Extra arguments given to atom %s: %s'
150- % (atom_name , list (extra_args )))
155+ raise ValueError (
156+ 'Extra arguments given to atom %s: %s'
157+ % (atom_name , list (extra_args ))
158+ )
151159
152160 # NOTE(imelnikov): don't use set to preserve order in error message
153161 missing_args = [arg for arg in req_args if arg not in required ]
154162 if missing_args :
155- raise ValueError ('Missing arguments for atom %s: %s'
156- % (atom_name , missing_args ))
163+ raise ValueError (
164+ 'Missing arguments for atom %s: %s' % (atom_name , missing_args )
165+ )
157166 return required , optional
158167
159168
@@ -244,9 +253,18 @@ class Atom(metaclass=abc.ABCMeta):
244253
245254 default_provides = None
246255
247- def __init__ (self , name = None , provides = None , requires = None ,
248- auto_extract = True , rebind = None , inject = None ,
249- ignore_list = None , revert_rebind = None , revert_requires = None ):
256+ def __init__ (
257+ self ,
258+ name = None ,
259+ provides = None ,
260+ requires = None ,
261+ auto_extract = True ,
262+ rebind = None ,
263+ inject = None ,
264+ ignore_list = None ,
265+ revert_rebind = None ,
266+ revert_requires = None ,
267+ ):
250268
251269 if provides is None :
252270 provides = self .default_provides
@@ -263,8 +281,9 @@ def __init__(self, name=None, provides=None, requires=None,
263281 self .rebind , exec_requires , self .optional = self ._build_arg_mapping (
264282 self .execute ,
265283 requires = requires ,
266- rebind = rebind , auto_extract = auto_extract ,
267- ignore_list = ignore_list
284+ rebind = rebind ,
285+ auto_extract = auto_extract ,
286+ ignore_list = ignore_list ,
268287 )
269288
270289 revert_ignore = ignore_list + list (_default_revert_args )
@@ -273,29 +292,42 @@ def __init__(self, name=None, provides=None, requires=None,
273292 requires = revert_requires or requires ,
274293 rebind = revert_rebind or rebind ,
275294 auto_extract = auto_extract ,
276- ignore_list = revert_ignore
295+ ignore_list = revert_ignore ,
296+ )
297+ (self .revert_rebind , addl_requires , self .revert_optional ) = (
298+ revert_mapping
277299 )
278- (self .revert_rebind , addl_requires ,
279- self .revert_optional ) = revert_mapping
280300
281301 # TODO(bnemec): This should be documented as an ivar, but can't be due
282302 # to https://github.com/sphinx-doc/sphinx/issues/2549
283303 #: A :py:class:`~taskflow.types.sets.OrderedSet` of inputs this atom
284304 #: requires to function.
285305 self .requires = exec_requires .union (addl_requires )
286306
287- def _build_arg_mapping (self , executor , requires = None , rebind = None ,
288- auto_extract = True , ignore_list = None ):
289-
290- required , optional = _build_arg_mapping (self .name , requires , rebind ,
291- executor , auto_extract ,
292- ignore_list = ignore_list )
307+ def _build_arg_mapping (
308+ self ,
309+ executor ,
310+ requires = None ,
311+ rebind = None ,
312+ auto_extract = True ,
313+ ignore_list = None ,
314+ ):
315+
316+ required , optional = _build_arg_mapping (
317+ self .name ,
318+ requires ,
319+ rebind ,
320+ executor ,
321+ auto_extract ,
322+ ignore_list = ignore_list ,
323+ )
293324 # Form the real rebind mapping, if a key name is the same as the
294325 # key value, then well there is no rebinding happening, otherwise
295326 # there will be.
296327 rebind = collections .OrderedDict ()
297- for (arg_name , bound_name ) in itertools .chain (required .items (),
298- optional .items ()):
328+ for arg_name , bound_name in itertools .chain (
329+ required .items (), optional .items ()
330+ ):
299331 rebind .setdefault (arg_name , bound_name )
300332 requires = sets .OrderedSet (required .values ())
301333 optional = sets .OrderedSet (optional .values ())
0 commit comments