Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Removed unnecessarily changing tuple output to list output #608

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

zli11010
Copy link

📥 Pull Request

📘 Description
Fixed this bug: #607

🧪 Testing
Ran my code that uses AgentOps and now it works. (Changing list to tuple doesn't affect what gets logged.)

Comment on lines -70 to -73
# If the function returns multiple values, record them all in the same event
if isinstance(returns, tuple):
returns = list(returns)

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of removing these functions, we can instead do what we intended at fist-- just return a tuple

if istinatnce(returns, tuple):
    returns = tuple(returns)

Removing these lines of code altogether will have unintended consequences.

Copy link
Author

@zli11010 zli11010 Dec 29, 2024

Choose a reason for hiding this comment

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

May I ask what the suggested change does? It seems (in most cases) equivalent to removing the two lines of code.

Unfortunately your suggested change would still break the code I'm using, since the code checks the output of the function is an instance of a specific subclass of tuple (more specifically, a custom namedtuple). Maybe one could argue that this is bad practice, but I believe it's more important that a decorator that does logging doesn't change the output of the function.

Copy link
Contributor

Choose a reason for hiding this comment

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

but AFAIK the only reason the tuple was being cast to a list was so that it can be dumped into a JSON, but json.dumps actually handles that automatically.

Indeed that should be handled by a JSONEncoder which is where these sorts of casts belong

@areibman
Copy link
Contributor

Left a review @zli11010-- should be an easy fix! Please let me know if it still causes problems with the repo you're trying

@teocns
Copy link
Contributor

teocns commented Dec 29, 2024

@areibman can we have more documentation around the expected functionality of returns? I too had a hard time figuring out, maybe some docstrings will do 👍

@zli11010
Copy link
Author

zli11010 commented Dec 29, 2024

@areibman Since you had concerns about deleting the lines, I tried to keep the original semantics with the only change being fixing the fact that the type casting modified the output of the original function. Hopefully that's better!

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.

4 participants