Skip to content

Conversation

@nordby
Copy link
Contributor

@nordby nordby commented Apr 18, 2025

Convert string indices to int in index() function

Closes #4591

Description

This PR modifies the index() utility function to automatically convert string indices (e.g., "0") to integers, preventing TypeError: list indices must be integers or slices, not str errors that occurred when indices were passed as strings.

Changes

def index(iterable, index) -> any:
    if isinstance(index, str) and index.isdigit():  # Safely convert string to int
        index = int(index)
    return iterable[index]

Convert index to int

Signed-off-by: nordby <34568878+nordby@users.noreply.github.com>
@vercel
Copy link

vercel bot commented Apr 18, 2025

@nordby is attempting to deploy a commit to the KeepHQ Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 18, 2025
@CLAassistant
Copy link

CLAassistant commented Apr 18, 2025

CLA assistant check
All committers have signed the CLA.

@dosubot dosubot bot added the Bug Something isn't working label Apr 18, 2025
@nordby nordby changed the title issue #4591 fix(utils): convert string indices to int in index() function to prevent TypeError Apr 18, 2025
Copy link
Member

@talboren talboren left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 18, 2025
@vercel
Copy link

vercel bot commented Apr 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
keep ⬜️ Ignored (Inspect) Visit Preview Apr 18, 2025 5:54pm

@talboren talboren merged commit b88d3a8 into keephq:main Apr 18, 2025
11 of 13 checks passed
@github-actions
Copy link
Contributor

🏆 Fantastic work @nordby! Your very first PR to keep has been merged! 🎉🥳

You've just taken your first step into open-source, and we couldn't be happier to have you onboard. 🙌
If you're feeling adventurous, why not dive into another issue and keep contributing? The community would love to see more from you! 🚀

For any support, feel free to reach out on the community: https://slack.keephq.dev. Happy coding! 👩‍💻👨‍💻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Functions keep.index doesn't work as expected

3 participants