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

Implement set.update method #573

Merged
merged 4 commits into from
Jan 27, 2025
Merged

Conversation

andponlin-canva
Copy link
Contributor

The method update on the type set is available in the Bazel implementation of Starlark, but unfortunately not this Go implementation. This PR will augment the set implementation to also support the update method.

The `update` method on the `set` is defined
in the Starlark specification [1] but is not
present in the starlark-go implementation.
This change introduces this functionality.

[1] https://github.com/bazelbuild/starlark/blob/master/spec.md#setupdate
Copy link
Collaborator

@adonovan adonovan left a comment

Choose a reason for hiding this comment

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

Thanks for this fix!

Copy link
Collaborator

@adonovan adonovan left a comment

Choose a reason for hiding this comment

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

Thanks again.

switch v := arg.(type) {
receiverSet := b.Receiver().(*Set)

// factored out into a function so that the `defer` is scoped to this iterable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point; but the comment isn't necessary as the code speaks for itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fact that the defer is in the function is obvious but the rationale is probably not so obvious.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's fairly common to call a function literal to reduce the scope of a defer.

@adonovan adonovan merged commit 2fb1215 into google:master Jan 27, 2025
13 checks passed
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.

2 participants