Skip to content

Commit e2bc2a7

Browse files
amuelleragramfort
authored andcommitted
add __dir__ to bunch for better autocomplete (scikit-learn#7090)
1 parent 1ad6fe3 commit e2bc2a7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

sklearn/datasets/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def __init__(self, **kwargs):
5151
def __setattr__(self, key, value):
5252
self[key] = value
5353

54+
def __dir__(self):
55+
return self.keys()
56+
5457
def __getattr__(self, key):
5558
try:
5659
return self[key]

sklearn/datasets/tests/test_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,9 @@ def test_bunch_pickle_generated_with_0_16_and_read_with_0_17():
223223
bunch_from_pkl.key = 'changed'
224224
assert_equal(bunch_from_pkl.key, 'changed')
225225
assert_equal(bunch_from_pkl['key'], 'changed')
226+
227+
228+
def test_bunch_dir():
229+
# check that dir (important for autocomplete) shows attributes
230+
data = load_iris()
231+
assert_true("data" in dir(data))

0 commit comments

Comments
 (0)