[3.12] gh-114552: Update __dir__ method docs: it allows returning an iterable (GH-114662) (#115234)

gh-114552: Update `__dir__` method docs: it allows returning an iterable (GH-114662)
(cherry picked from commit e19103a346)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2024-02-10 09:50:31 +01:00 committed by GitHub
parent 321ec5e0fe
commit 7cc205872d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View file

@ -586,6 +586,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):