Commits

Amaury Forgeot d'Arc committed b9757b3

Add FunctionType.__globals__, and update some tests because "import new" fails with py3k.

Comments (0)

Files changed (2)

pypy/interpreter/test/test_function.py

         assert f.__dict__ is f.func_dict
         assert f.__code__ is f.func_code
         assert f.__defaults__ is f.func_defaults
+        assert f.__globals__ is f.func_globals
         assert hasattr(f, '__class__')
 
     def test_classmethod(self):
         class A(object):
             def __call__(self, x):
                 return x
-        import new
-        im = new.instancemethod(A(), 3)
+        import types
+        im = types.MethodType(A(), 3)
         assert im() == 3
 
     def test_method_w_callable_call_function(self):
         class A(object):
             def __call__(self, x, y):
                 return x+y
-        import new
-        im = new.instancemethod(A(), 3)
+        import types
+        im = types.MethodType(A(), 3)
         assert map(im, [4]) == [7]
 
     def test_unbound_typecheck(self):
         assert Fun[:2] == ('Fun', ())
 
     def test_unbound_abstract_typecheck(self):
-        import new
+        import types
         def f(*args):
             return args
-        m = new.instancemethod(f, None, "foobar")
+        m = types.MethodType(f, None, "foobar")
         raises(TypeError, m)
         raises(TypeError, m, None)
         raises(TypeError, m, "egg")
 
-        m = new.instancemethod(f, None, (str, int))     # really obscure...
+        m = types.MethodType(f, None, (str, int))     # really obscure...
         assert m(4) == (4,)
         assert m("uh") == ("uh",)
         raises(TypeError, m, [])
         BSub1.__bases__ = (BBase,)
         BSub2.__bases__ = (BBase,)
         x = MyInst(BSub1)
-        m = new.instancemethod(f, None, BSub1)
+        m = types.MethodType(f, None, BSub1)
         assert m(x) == (x,)
         raises(TypeError, m, MyInst(BBase))
         raises(TypeError, m, MyInst(BSub2))
         raises(TypeError, m, MyInst(42))
 
     def test_invalid_creation(self):
-        import new
+        import types
         def f(): pass
-        raises(TypeError, new.instancemethod, f, None)
+        raises(TypeError, types.MethodType, f, None)
 
     def test_empty_arg_kwarg_call(self):
         def f():

pypy/interpreter/typedef.py

     __name__ = getset_func_name,
     __dict__ = getset_func_dict,
     __defaults__ = getset_func_defaults,
+    __globals__ = interp_attrproperty_w('w_func_globals', cls=Function),
     __module__ = getset___module__,
     __weakref__ = make_weakref_descr(Function),
     )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.