Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove py2-compat hack from bunch.__dir__ #906

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading