Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Currently, we have the instance method
Target.has_field()
(andTarget.has_fields()
), e.g.tgt.has_field(PythonSources)
.In some cases, though, we need a classmethod rather than an instance method to be able to do this same type of check. For example, when generating an error message when running
./v2 binary
on an invalid target type, we want to be able to calculate every single target type that does work with the goal. To do that, we need to be able to iterate over everyType[Target]
registered and callPythonLibrary.has_fields([EntryPoint, PythonBinarySources])
so that we can decide ifPythonLibrary
is a valid target type or not.The tricky part is that we must support plugin fields added to pre-existing target types, which are achieved by plugin authors registering
UnionRule(PythonLibrary.PluginField, MyCustomField)
.Solution
Add
Target.class_has_field()
andTarget.class_has_fields()
.Factor out
Target.has_field()
to deduplicate between the classmethod and instance method.