Skip to content

fix: State.keys() now displays only keys without values (#409)#585

Merged
skrawcz merged 3 commits intoapache:mainfrom
agam1092005:main
Oct 17, 2025
Merged

fix: State.keys() now displays only keys without values (#409)#585
skrawcz merged 3 commits intoapache:mainfrom
agam1092005:main

Conversation

@agam1092005
Copy link
Contributor

Fix State.keys() displaying values (#409)

Problem: State.keys() was showing both keys and values when printed, making it unusable with large objects (JSON responses, dataframes, embeddings).

Solution: Added custom StateKeys wrapper class that provides clean __repr__ showing only keys, while maintaining full KeysView compatibility (iteration, membership, length).

Changes:

  • Added StateKeys class with clean string representation
  • Override State.keys() to return StateKeys wrapper
  • Maintains backward compatibility for all KeysView operations

Testing:

  • All existing tests pass
  • Added comprehensive test coverage for new functionality
  • Verified fix resolves the reported issue

Fixes #409

Returns:
StateKeysView: A view object that shows only keys in its string representation
"""
return StateKeysView(self._state.keys())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe returning list(self._state) (implicitly self._state.keys()) would be sufficient.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'd vote for this simpler option if it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! The simpler approach is much better. Kindly check latest commit...

Copy link
Contributor

@skrawcz skrawcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove the redundancy in the tests please? e.g. just test for the exact return -- it covers all the cases.

@skrawcz
Copy link
Contributor

skrawcz commented Oct 4, 2025

@elijahbenizzy any concerns on exposing .keys() on state?

@agam1092005
Copy link
Contributor Author

Kindly check the latest commit and let me know any changes if required

@skrawcz skrawcz merged commit e12b3bb into apache:main Oct 17, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qol: State.keys() should only display keys and not values.

3 participants