Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.3
Changeset: r75021:a81d1ddf3dfe
Date: 2014-12-18 22:36 +0100
http://bitbucket.org/pypy/pypy/changeset/a81d1ddf3dfe/

Log:    Add Function.__qualname__, basic form.

diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -39,6 +39,7 @@
                  closure=None, w_ann=None, forcename=None):
         self.space = space
         self.name = forcename or code.co_name
+        self.qualname = self.name.decode('utf-8')  # So far
         self.w_doc = None   # lazily read from code.getdocstring()
         self.code = code       # Code instance
         self.w_func_globals = w_globals  # the globals dictionary
@@ -400,7 +401,20 @@
         except OperationError, e:
             if e.match(space, space.w_TypeError):
                 raise OperationError(space.w_TypeError,
-                                     space.wrap("func_name must be set "
+                                     space.wrap("__name__ must be set "
+                                                "to a string object"))
+            raise
+
+    def fget_func_qualname(self, space):
+        return space.wrap(self.qualname)
+
+    def fset_func_qualname(self, space, w_name):
+        try:
+            self.qualname = space.unicode_w(w_name)
+        except OperationError, e:
+            if e.match(space, space.w_TypeError):
+                raise OperationError(space.w_TypeError,
+                                     space.wrap("__qualname__ must be set "
                                                 "to a string object"))
             raise
 
diff --git a/pypy/interpreter/test/test_function.py 
b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -21,6 +21,13 @@
         assert f.__name__ == 'f'
         assert f.__module__ == 'mymodulename'
 
+    def test_qualname(self):
+        def f(): pass
+        assert f.__qualname__ == 'f'
+        f.__qualname__ = 'qualname'
+        assert f.__qualname__ == 'qualname'
+        raises(TypeError, "f.__qualname__ = b'name'")
+
     def test_annotations(self):
         def f(): pass
         ann = f.__annotations__
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -814,6 +814,8 @@
                                   Function.fset_func_code)
 getset_func_name = GetSetProperty(Function.fget_func_name,
                                   Function.fset_func_name)
+getset_func_qualname = GetSetProperty(Function.fget_func_qualname,
+                                      Function.fset_func_qualname)
 getset_func_annotations = GetSetProperty(Function.fget_func_annotations,
                                         Function.fset_func_annotations,
                                         Function.fdel_func_annotations)
@@ -831,6 +833,7 @@
     __code__ = getset_func_code,
     __doc__ = getset_func_doc,
     __name__ = getset_func_name,
+    __qualname__ = getset_func_qualname,
     __dict__ = getset_func_dict,
     __defaults__ = getset_func_defaults,
     __kwdefaults__ = getset_func_kwdefaults,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to