Commits

Philip Jenvey  committed f5ceeba

emit different NameErrors for LOAD_GLOBAL/NAME

  • Participants
  • Parent commits 94b14a1
  • Branches py3k

Comments (0)

Files changed (1)

File pypy/interpreter/pyopcode.py

             if w_value is not None:
                 self.pushvalue(w_value)
                 return
-        self.LOAD_GLOBAL(nameindex, next_instr)    # fall-back
+        # fall-back
+        self.LOAD_GLOBAL(nameindex, next_instr, "name '%s' is not defined")
 
-    def _load_global(self, varname):
+    def _load_global(self, varname, errmsg):
         w_value = self.space.finditem_str(self.w_globals, varname)
         if w_value is None:
             # not in the globals, now look in the built-ins
             w_value = self.get_builtin().getdictvalue(self.space, varname)
             if w_value is None:
-                self._load_global_failed(varname)
+                self._load_global_failed(errmsg, varname)
         return w_value
     _load_global._always_inline_ = True
 
-    def _load_global_failed(self, varname):
-        message = "global name '%s' is not defined"
-        raise operationerrfmt(self.space.w_NameError, message, varname)
+    def _load_global_failed(self, errmsg, varname):
+        raise operationerrfmt(self.space.w_NameError, errmsg, varname)
     _load_global_failed._dont_inline_ = True
 
-    def LOAD_GLOBAL(self, nameindex, next_instr):
-        self.pushvalue(self._load_global(self.getname_u(nameindex)))
+    def LOAD_GLOBAL(self, nameindex, next_instr,
+                    errmsg="global name '%s' is not defined"):
+        self.pushvalue(self._load_global(self.getname_u(nameindex), errmsg))
     LOAD_GLOBAL._always_inline_ = True
 
     def DELETE_FAST(self, varindex, next_instr):