diff -r fe813f5711a5 Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py Thu Jun 09 10:00:42 2011 -0500 +++ b/Lib/test/test_builtin.py Thu Jun 09 15:46:48 2011 -0400 @@ -317,7 +317,14 @@ f = Foo() self.assertTrue(dir(f) == ["ga", "kan", "roo"]) - # dir(obj__dir__not_list) + # dir(obj_using __dir__nonlist_sequence) + class Foo(object): + def __dir__(self): + return ('xyz', 'pdq', 'lmno') + f = Foo() + self.assertTrue(dir(f) == ['lmno', 'pdq', 'xyz']) + + # dir(obj__dir__not_sequence) class Foo(object): def __dir__(self): return 7 diff -r fe813f5711a5 Objects/object.c --- a/Objects/object.c Thu Jun 09 10:00:42 2011 -0500 +++ b/Objects/object.c Thu Jun 09 15:46:48 2011 -0400 @@ -1907,6 +1907,7 @@ PyObject *result = NULL; static PyObject *dir_str = NULL; PyObject *dirfunc; + PyObject *oldresult; assert(obj); if (PyInstance_Check(obj)) { @@ -1940,13 +1941,10 @@ return NULL; /* result must be a list */ - /* XXX(gbrandl): could also check if all items are strings */ if (!PyList_Check(result)) { - PyErr_Format(PyExc_TypeError, - "__dir__() must return a list, not %.200s", - Py_TYPE(result)->tp_name); - Py_DECREF(result); - result = NULL; + oldresult = result; + result = PySequence_List(result); + Py_DECREF(oldresult); } }