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

add copy and __add__ methods to ContextBuilder #16

Closed
wants to merge 2 commits into from

Conversation

granawkins
Copy link
Member

No description provided.

duplicate.context[path_str] = data
else:
duplicate.context[path_str]["lines"].update(data["lines"])
duplicate.context[path_str]["tags"].update(data["tags"])
Copy link

Choose a reason for hiding this comment

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

It seems you are using update to merge dictionaries. However, update for set and dict doesn't account for values like lists within the dictionaries. For duplicate.context[path_str]['tags'], if 'tags' are lists, this could lead to undesired behavior. You may want to consider using a deeper merge function or a library function if tags contain nested structures.

if path_str not in duplicate.context:
duplicate.context[path_str] = data
else:
duplicate.context[path_str]["lines"].update(data["lines"])
Copy link

Choose a reason for hiding this comment

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

Using update on duplicate.context[path_str]['lines'] can be problematic if lines contains an object that doesn't have a well-defined union operation, such as sets of custom objects. Ensure that all objects stored in lines support a direct update operation or convert them to a compatible type first.

comments
)
return duplicate

Copy link

Choose a reason for hiding this comment

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

The check if not path: here will stop execution if path is None or empty. This is fine if this is expected to never be a valid value, but it could lead to skipped logic if a valid 'path' can sometimes be falsy (e.g., an empty string which might be a valid relative path for some systems).

@mentatai
Copy link

mentatai bot commented Apr 25, 2024

MENTAT CODE REVIEW IN ACTIVE DEVELOPMENT. Only in use on mentat and internal repos.
Please Reply with feedback.

The add and copy methods you've added to ContextBuilder are critical for merging context states effectively, but ensure the merging operations consider all data types and potential edge cases to avoid logic errors. Review the use of update and handling of falsy values carefully.

@granawkins granawkins closed this Apr 25, 2024
@granawkins granawkins deleted the context-builder-methods branch April 25, 2024 17:52
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.

1 participant