[pypy-commit] pypy py3.3: issue1835: (numerodix) fix dir(None)

pjenvey noreply at buildbot.pypy.org
Mon Aug 4 01:35:11 CEST 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3.3
Changeset: r72687:b8010ea183a7
Date: 2014-08-03 16:01 -0700
http://bitbucket.org/pypy/pypy/changeset/b8010ea183a7/

Log:	issue1835: (numerodix) fix dir(None)

diff --git a/pypy/module/__builtin__/app_inspect.py b/pypy/module/__builtin__/app_inspect.py
--- a/pypy/module/__builtin__/app_inspect.py
+++ b/pypy/module/__builtin__/app_inspect.py
@@ -44,7 +44,9 @@
     obj = args[0]
     dir_meth = lookup_special(obj, '__dir__')
     if dir_meth is not None:
+        # obscure: lookup_special won't bind None.__dir__!
+        result = dir_meth(obj) if obj is None else dir_meth()
         # Will throw TypeError if not iterable
-        return sorted(dir_meth())
+        return sorted(result)
     # we should never reach here since object.__dir__ exists
     return []
diff --git a/pypy/module/__builtin__/test/test_dir.py b/pypy/module/__builtin__/test/test_dir.py
--- a/pypy/module/__builtin__/test/test_dir.py
+++ b/pypy/module/__builtin__/test/test_dir.py
@@ -100,3 +100,6 @@
         for t in [int, list, tuple, set, str]:
             raises(TypeError, t.__dir__)
             assert dir(t) == sorted(t().__dir__())
+
+    def test_dir_none(self):
+        assert dir(None) == sorted(None.__dir__())


More information about the pypy-commit mailing list