From 524a906be4443523f3490cbc98bb041c703bb917 Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Mon, 10 Jun 2024 11:37:57 -0700 Subject: [PATCH 1/3] Remove py2-compat hack from bunch.__dir__ --- tests/utils/test_bunch.py | 5 ++++- traitlets/utils/bunch.py | 3 +-- 2 files changed, 5 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..7072e285 100644 --- a/traitlets/utils/bunch.py +++ b/traitlets/utils/bunch.py @@ -23,7 +23,6 @@ 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 = dir(Bunch) names.extend(self.keys()) return names From f07b6be530aef1729cf889e6f22e6b6c811e8148 Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 28 Nov 2024 13:11:37 +0100 Subject: [PATCH 2/3] use super dir now that we can --- traitlets/utils/bunch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traitlets/utils/bunch.py b/traitlets/utils/bunch.py index 7072e285..045dc88d 100644 --- a/traitlets/utils/bunch.py +++ b/traitlets/utils/bunch.py @@ -23,6 +23,6 @@ def __setattr__(self, key: str, value: Any) -> None: self.__setitem__(key, value) def __dir__(self) -> list[str]: - names = dir(Bunch) + names = super().__dir__() names.extend(self.keys()) return names From 3f9fac49e12a1606e53eb3be6896f04969ba4038 Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 28 Nov 2024 13:13:59 +0100 Subject: [PATCH 3/3] satisfy typing --- traitlets/utils/bunch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/traitlets/utils/bunch.py b/traitlets/utils/bunch.py index 045dc88d..b1eb6c28 100644 --- a/traitlets/utils/bunch.py +++ b/traitlets/utils/bunch.py @@ -23,6 +23,7 @@ def __setattr__(self, key: str, value: Any) -> None: self.__setitem__(key, value) def __dir__(self) -> list[str]: - names = super().__dir__() + names: list[str] = [] + names.extend(super().__dir__()) names.extend(self.keys()) return names