From 6d4dbac54e78c13a808966f09c72ffe71c8ca332 Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Thu, 28 Nov 2024 04:20:12 -0800 Subject: [PATCH] Remove py2-compat hack from bunch.__dir__ (#906) Co-authored-by: Min RK --- tests/utils/test_bunch.py | 5 ++++- traitlets/utils/bunch.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/utils/test_bunch.py b/tests/utils/test_bunch.py index 90efe982..98bf2620 100644 --- a/tests/utils/test_bunch.py +++ b/tests/utils/test_bunch.py @@ -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) diff --git a/traitlets/utils/bunch.py b/traitlets/utils/bunch.py index 498563e0..b1eb6c28 100644 --- a/traitlets/utils/bunch.py +++ b/traitlets/utils/bunch.py @@ -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