This is an automated email from the ASF dual-hosted git repository.
skrawcz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/burr.git
The following commit(s) were added to refs/heads/main by this push:
new e12b3bbe fix: State.keys() now displays only keys without values
(#409) (#585)
e12b3bbe is described below
commit e12b3bbedcda1cf6cc7359b5796d52987798d7d1
Author: Agampreet Singh <[email protected]>
AuthorDate: Sat Oct 18 00:44:17 2025 +0530
fix: State.keys() now displays only keys without values (#409) (#585)
This adds a .keys() method to return a list of keys in state.
* fix: State.keys() now displays only keys without values (#409)
* fix: return list from State.keys() to avoid displaying values (#409)
* removed redundant tests
---
burr/core/state.py | 21 ++++++++++++++++++++-
tests/core/test_state.py | 14 ++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/burr/core/state.py b/burr/core/state.py
index a9a31ac1..d82e6f4b 100644
--- a/burr/core/state.py
+++ b/burr/core/state.py
@@ -22,7 +22,18 @@ import importlib
import inspect
import logging
from functools import cached_property
-from typing import Any, Callable, Dict, Generic, Iterator, Mapping, Optional,
TypeVar, Union
+from typing import (
+ Any,
+ Callable,
+ Dict,
+ Generic,
+ Iterator,
+ List,
+ Mapping,
+ Optional,
+ TypeVar,
+ Union,
+)
from burr.core import serde
from burr.core.typing import DictBasedTypingSystem, TypingSystem
@@ -460,6 +471,14 @@ class State(Mapping, Generic[StateType]):
def __iter__(self) -> Iterator[Any]:
return iter(self._state)
+ def keys(self):
+ """Returns a list of the state keys only (without values for cleaner
display).
+
+ Returns:
+ list: A list of state keys
+ """
+ return list(self._state)
+
def __repr__(self):
return self.get_all().__repr__() # quick hack
diff --git a/tests/core/test_state.py b/tests/core/test_state.py
index dede0e99..1c19b857 100644
--- a/tests/core/test_state.py
+++ b/tests/core/test_state.py
@@ -226,3 +226,17 @@ def test_state_apply_keeps_typing_system():
state = State({"foo": "bar"}, typing_system=SimpleTypingSystem())
assert state.update(foo="baz").typing_system is state.typing_system
assert state.subset("foo").typing_system is state.typing_system
+
+
+def test_state_keys_returns_list():
+ """Test that State.keys() returns a list (fixes #409)"""
+ state = State({"a": 1, "b": 2, "c": 3})
+ keys = state.keys()
+
+ # Should return a list with the correct keys
+ assert isinstance(keys, list)
+ assert keys == ["a", "b", "c"]
+
+ # Test with empty state
+ empty_state = State()
+ assert empty_state.keys() == []