code: def infer_name(self, context=None):
      
      frame, stmts = self.lookup(self.name)
      if not stmts:
          # Try to see if the name is enclosed in a nested function
          # and use the higher (first function) scope for searching.
          parent_function = _higher_function_scope(self.scope())
          if parent_function:
              _, stmts = parent_function.lookup(self.name)
  
          if not stmts:
              raise exceptions.NameInferenceError(
                  name=self.name, scope=self.scope(), context=context
              )
      context = contextmod.copy_context(context)
      context.lookupname = self.name
      return bases._infer_stmts(stmts, context, frame)
docs: infer a Name: use name lookup rules