parameters: (module_context)
return_statement: return added
docstring: Detect sys.path modifications within module.
docstring_summary: Detect sys.path modifications within module.
docstring_tokens: Detect sys . path modifications within module .
function: def check_sys_path_modifications(module_context):
      """
      Detect sys.path modifications within module.
      """
      def get_sys_path_powers(names):
          for name in names:
              power = name.parent.parent
              if power.type in ('power', 'atom_expr'):
                  c = power.children
                  if c[0].type == 'name' and c[0].value == 'sys' \
                          and c[1].type == 'trailer':
                      n = c[1].children[1]
                      if n.type == 'name' and n.value == 'path':
                          yield name, power
  
      if module_context.tree_node is None:
          return []
  
      added = []
      try:
          possible_names = module_context.tree_node.get_used_names()['path']
      except KeyError:
          pass
      else:
          for name, power in get_sys_path_powers(possible_names):
              expr_stmt = power.parent
              if len(power.children) >= 4:
                  added.extend(
                      _paths_from_list_modifications(
                          module_context, *power.children[2:4]
                      )
                  )
              elif expr_stmt is not None and expr_stmt.type == 'expr_stmt':
                  added.extend(_paths_from_assignment(module_context, expr_stmt))
      return added
function_tokens: def check_sys_path_modifications ( module_context ) : def get_sys_path_powers ( names ) : for name in names : power = name . parent . parent if power . type in ( 'power' , 'atom_expr' ) : c = power . children if c [ 0 ] . type == 'name' and c [ 0 ] . value == 'sys' and c [ 1 ] . type == 'trailer' : n = c [ 1 ] . children [ 1 ] if n . type == 'name' and n . value == 'path' : yield name , power if module_context . tree_node is None : return [ ] added = [ ] try : possible_names = module_context . tree_node . get_used_names ( ) [ 'path' ] except KeyError : pass else : for name , power in get_sys_path_powers ( possible_names ) : expr_stmt = power . parent if len ( power . children ) >= 4 : added . extend ( _paths_from_list_modifications ( module_context , * power . children [ 2 : 4 ] ) ) elif expr_stmt is not None and expr_stmt . type == 'expr_stmt' : added . extend ( _paths_from_assignment ( module_context , expr_stmt ) ) return added