gh-114552: Update __dir__ method docs: it allows returning an iterable (#114662)

This commit is contained in:
Nikita Sobolev 2024-02-10 11:34:23 +03:00 committed by GitHub
parent b2d9d134dc
commit e19103a346
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View file

@ -611,6 +611,14 @@ class BuiltinTest(unittest.TestCase):
self.assertIsInstance(res, list)
self.assertTrue(res == ["a", "b", "c"])
# dir(obj__dir__iterable)
class Foo(object):
def __dir__(self):
return {"b", "c", "a"}
res = dir(Foo())
self.assertIsInstance(res, list)
self.assertEqual(sorted(res), ["a", "b", "c"])
# dir(obj__dir__not_sequence)
class Foo(object):
def __dir__(self):