Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Problem Currently, we have the instance method `Target.has_field()` (and `Target.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 every `Type[Target]` registered and call `PythonLibrary.has_fields([EntryPoint, PythonBinarySources])` so that we can decide if `PythonLibrary` 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()` and `Target.class_has_fields()`. Factor out `Target.has_field()` to deduplicate between the classmethod and instance method.
- Loading branch information
1 parent
5ccb04d
commit 250ed9d
Showing
2 changed files
with
85 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters