-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 StarlarkIndexable.getIndex implementations that return null. #15344
Conversation
They should return Starlark.NONE instead. Part of Optional Toolchains (bazelbuild#14726).
I was originally going to fix this in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that for consistency with dict
(and python), getIndex() should throw an EvalException if the key is missing.
Hello @katre, Can you please share the update on the review comments. Thanks! |
@sgowroji: Please note the timestamps: @tetromino commented at about 10pm ET last night, it is currently not even 8am ET now. I appreciate that you are keeping on top of PRs, but please give all contributors at least 12 hours to read and respond. @tetromino: I will respond once I actually start my work day and can think through your response. |
There are three cases here:
The entire point of the work I am doing is to allow for optional toolchains, and the design we settled on there was that Does this make sense, @tetromino ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@katre - understood. I originally misread the code, but I now see that for both ConstraintCollection and StarlarkToolchainContext, getIndex and containsKey behave consistently.
One nit I suggest fixing is update the docstring in ToolchainContextApi.java to explain when context["//pkg:my_toolchain_type"] can be None.
Besides that, LGTM.
… throw errors for unknown getIndex keys.
Good point about the docs, fixed that. Let me know if this is sufficiently clear. |
if (result == null) { | ||
result = Starlark.NONE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really sorry for being unclear (and for being mistaken in my first comment) - the previous version of the code you hard (returning Starlark.NONE) was correct. For consistency with dict
's behavior, we don't want getIndex(x) to throw if containsKey(x) returns true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. Changed it back.
They should return Starlark.NONE instead.
Part of Optional Toolchains (#14726).