(self, node)
return node
Visits expressions and check if they are in the form of either 
      `environment.define` or `environment.undefine` properly stores the 
      arguments definition as string.
Visits expressions and check if they are in the form of either 
      `environment.define` or `environment.undefine` properly stores the 
      arguments definition as string.
Visits expressions and check if they are in the form of either environment . define or environment . undefine properly stores the arguments definition as string .
def visit_Expr(self, node):
    """
      Visits expressions and check if they are in the form of either 
      `environment.define` or `environment.undefine` properly stores the 
      arguments definition as string.
    """
    value = node.value
    if isinstance(value, ast.Call):
      function = value.func
      if isinstance(function, ast.Attribute):
        attribute = function.value
        if isinstance(attribute, ast.Name):
          name = attribute.id
          if name == 'environment' and function.attr == 'define' and not value.keywords:
            if not len(value.args) == 2:
              raise EnvironmentDefinitionError('environment.define calls receive 2 arguments')
              
            self._ensureType(
              obj=value.args[0], 
              klass=ast.Name, 
              error_message='Type mismatch. environment.define receives a function as first argument.'
            )
            
            self._ensureType(
              obj=value.args[1], 
              klass=ast.Str, 
              error_message='Type mismatch. environment.define receives a string as second argument.'
            )
            
            func_name = value.args[0].id
            func_alias = value.args[1].s
            function_node = self.function_dict[func_name]
            function_string = astor.to_source(function_node)
            self.environment_setup_dict[func_name] = {
              "code": function_string,
              "alias": func_alias
            }
          elif name == 'environment' and function.attr == 'define' and value.keywords:
            for keyword in value.keywords:
              arg_name = keyword.arg
              arg_value_node = keyword.value
              
              # The value can be a number, string or name. We need to handle 
              # them separatedly. This dict trick was used to avoid the very
              # ugly if.
              node_value_dict = {
                ast.Num: lambda node: str(node.n),
                ast.Str: lambda node: node.s,
                ast.Name: lambda node: node.id
              }
              arg_value = node_value_dict[type(arg_value_node)](arg_value_node)
              self.environment_var_dict[arg_name] = arg_value
          elif name == 'environment' and function.attr == 'undefine':
            self._ensureType(
              obj=value.args[0], 
              klass=ast.Str, 
              call_type='undefine',
              error_message='Type mismatch. environment.undefine receives only a string as argument.'
            )
            
            func_alias = value.args[0].s
            self.environment_remove_list.append(func_alias)
          elif name == 'environment' and function.attr == 'clearAll':
            self.environment_clear_all = True
          elif name == 'environment'and function.attr == 'showSetup':
            self.show_environment_setup = True
    return node
def visit_Expr ( self , node ) : value = node . value if isinstance ( value , ast . Call ) : function = value . func if isinstance ( function , ast . Attribute ) : attribute = function . value if isinstance ( attribute , ast . Name ) : name = attribute . id if name == 'environment' and function . attr == 'define' and not value . keywords : if not len ( value . args ) == 2 : raise EnvironmentDefinitionError ( 'environment.define calls receive 2 arguments' ) self . _ensureType ( obj = value . args [ 0 ] , klass = ast . Name , error_message = 'Type mismatch. environment.define receives a function as first argument.' ) self . _ensureType ( obj = value . args [ 1 ] , klass = ast . Str , error_message = 'Type mismatch. environment.define receives a string as second argument.' ) func_name = value . args [ 0 ] . id func_alias = value . args [ 1 ] . s function_node = self . function_dict [ func_name ] function_string = astor . to_source ( function_node ) self . environment_setup_dict [ func_name ] = { "code" : function_string , "alias" : func_alias } elif name == 'environment' and function . attr == 'define' and value . keywords : for keyword in value . keywords : arg_name = keyword . arg arg_value_node = keyword . value # The value can be a number, string or name. We need to handle  # them separatedly. This dict trick was used to avoid the very # ugly if. node_value_dict = { ast . Num : lambda node : str ( node . n ) , ast . Str : lambda node : node . s , ast . Name : lambda node : node . id } arg_value = node_value_dict [ type ( arg_value_node ) ] ( arg_value_node ) self . environment_var_dict [ arg_name ] = arg_value elif name == 'environment' and function . attr == 'undefine' : self . _ensureType ( obj = value . args [ 0 ] , klass = ast . Str , call_type = 'undefine' , error_message = 'Type mismatch. environment.undefine receives only a string as argument.' ) func_alias = value . args [ 0 ] . s self . environment_remove_list . append ( func_alias ) elif name == 'environment' and function . attr == 'clearAll' : self . environment_clear_all = True elif name == 'environment' and function . attr == 'showSetup' : self . show_environment_setup = True return node