Skip to content

Commit

Permalink
Remove py2-compat hack from bunch.__dir__ (#906)
Browse files Browse the repository at this point in the history
Co-authored-by: Min RK <benjaminrk@gmail.com>
  • Loading branch information
sethtroisi and minrk authored Nov 28, 2024
1 parent 9522ad6 commit 6d4dbac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion tests/utils/test_bunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ def test_bunch():

def test_bunch_dir():
b = Bunch(x=5, y=10)
assert "x" in dir(b)
assert "keys" in dir(b)
assert "x" in dir(b)
assert "z" not in dir(b)
b.z = 15
assert "z" in dir(b)
4 changes: 2 additions & 2 deletions traitlets/utils/bunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __setattr__(self, key: str, value: Any) -> None:
self.__setitem__(key, value)

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

0 comments on commit 6d4dbac

Please sign in to comment.