3030
3131
3232class AnnotatedVariablesExtractor (ast .NodeTransformer ):
33+ """AnnotatedVariablesExtractor removes the typing annotations
34+ from relative to ipython2cwl and identifies all the variables
35+ relative to an ipython2cwl typing annotation."""
3336 input_type_mapper : Dict [Tuple [str , ...], Tuple [str , str ]] = {
3437 (CWLFilePathInput .__name__ ,): (
3538 'File' ,
@@ -67,11 +70,15 @@ class AnnotatedVariablesExtractor(ast.NodeTransformer):
6770 }
6871
6972 def __init__ (self , * args , ** kwargs ):
73+ """Create an AnnotatedVariablesExtractor"""
7074 super ().__init__ (* args , ** kwargs )
7175 self .extracted_variables : List = []
7276 self .to_dump : List = []
7377
7478 def __get_annotation__ (self , type_annotation ):
79+ """Parses the annotation and returns it in a canonical format.
80+ If the annotation was a string 'CWLStringInput' the function
81+ will return you the object."""
7582 annotation = None
7683 if isinstance (type_annotation , ast .Name ):
7784 annotation = (type_annotation .id ,)
@@ -164,7 +171,8 @@ def visit_AnnAssign(self, node):
164171 pass
165172 return node
166173
167- def visit_Import (self , node : ast .Import ):
174+ def visit_Import (self , node : ast .Import ) -> Any :
175+ """Remove ipython2cwl imports """
168176 names = []
169177 for name in node .names : # type: ast.alias
170178 if name .name == 'ipython2cwl' or name .name .startswith ('ipython2cwl.' ):
@@ -177,6 +185,7 @@ def visit_Import(self, node: ast.Import):
177185 return None
178186
179187 def visit_ImportFrom (self , node : ast .ImportFrom ) -> Any :
188+ """Remove ipython2cwl imports """
180189 if node .module == 'ipython2cwl' or (node .module is not None and node .module .startswith ('ipython2cwl.' )):
181190 return None
182191 return node
@@ -188,8 +197,7 @@ class AnnotatedIPython2CWLToolConverter:
188197 with the described inputs & outputs.
189198 """
190199
191- _code : str
192- """The annotated python code to convert."""
200+ _code : str # The annotated python code to convert.
193201
194202 def __init__ (self , annotated_ipython_code : str ):
195203 """Creates an AnnotatedIPython2CWLToolConverter. If the annotated_ipython_code contains magic commands use the
@@ -198,7 +206,8 @@ def __init__(self, annotated_ipython_code: str):
198206 self ._code = annotated_ipython_code
199207 extractor = AnnotatedVariablesExtractor ()
200208 self ._tree = extractor .visit (ast .parse (self ._code ))
201- [self ._tree .body .extend (d ) for d in extractor .to_dump ]
209+ for d in extractor .to_dump :
210+ self ._tree .body .extend (d )
202211 self ._tree = ast .fix_missing_locations (self ._tree )
203212 self ._variables = []
204213 for variable in extractor .extracted_variables : # type: _VariableNameTypePair
0 commit comments