[pypy-dev] My first try: dir()

Seo Sanghyeon tinuviel at sparcs.kaist.ac.kr
Tue Sep 23 18:38:37 CEST 2003

Hello, everybody,

I followed the mailing list for some time, but haven't
touched the code yet.

Here's my first try, dir(), from your confused newbie.
For now, everything from Objectspace to Gateway is just
incomprehensible for me, but I will try...

I'm requesting for some comments. My try seems to work,
but I want to know how would you write the following,
and how to implement the rest of dir(), etc.

Index: builtin.py
--- builtin.py  (revision 1415)
+++ builtin.py  (working copy)
@@ -383,6 +383,20 @@
         except AttributeError:
             return False
+    def dir(self, w_object=None):
+        space = self.space
+        ob = space.unwrap(w_object)
+        if ob is None:
+            dic = self.locals()
+        elif type(ob) is Module:
+            dic = ob.w_dict
+        else:
+            w_exc = space.w_ValueError("Not implemented yet")
+            raise OperationError(space.w_ValueError, w_exc)
+        result = space.call_method(dic, 'keys')
+        space.call_method(result, 'sort')
+        return result
 # source code for the builtin xrange-class
 xrange_appsource = """if 1: 
     class xrange:

More information about the Pypy-dev mailing list