Skip to content

Commit 6d4dbac

Browse files
sethtroisiminrk
andauthored
Remove py2-compat hack from bunch.__dir__ (#906)
Co-authored-by: Min RK <[email protected]>
1 parent 9522ad6 commit 6d4dbac

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

tests/utils/test_bunch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ def test_bunch():
1414

1515
def test_bunch_dir():
1616
b = Bunch(x=5, y=10)
17-
assert "x" in dir(b)
1817
assert "keys" in dir(b)
18+
assert "x" in dir(b)
19+
assert "z" not in dir(b)
20+
b.z = 15
21+
assert "z" in dir(b)

traitlets/utils/bunch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __setattr__(self, key: str, value: Any) -> None:
2323
self.__setitem__(key, value)
2424

2525
def __dir__(self) -> list[str]:
26-
# py2-compat: can't use super because dict doesn't have __dir__
27-
names = dir({})
26+
names: list[str] = []
27+
names.extend(super().__dir__())
2828
names.extend(self.keys())
2929
return names

0 commit comments

Comments
 (0)