https://pantsbuild.org/ logo
#development
Title
# development
w

witty-crayon-22786

02/09/2022, 11:32 PM
total aside related to `FieldSet`… could
Target
use the same field-access mechanism?
…as an alternative to `target[Field]`…?
h

hundreds-father-404

02/09/2022, 11:39 PM
so,
target.resolve
? That doesn't work with the Target API wanting you to say which field you're looking for,
SingleSourceField
vs
SourceField
vs
PythonSourceField
You should declare it explicitly at your call site, not rely on whatever
tgt.source
is set to imo
w

witty-crayon-22786

02/09/2022, 11:40 PM
you can only have one value per alias though.
h

hundreds-father-404

02/09/2022, 11:41 PM
yeah, but it's a field-driven API, not target-driven API. It's an antipattern to be checking
isinstance(tgt, PythonSourceTarget)
. Violates extensibility of creating custom targets - we don't want you to have to subclass
PythonSourceTarget
when adding a new target
so, idiomatic rules would not know what
tgt
is. And that's the whole point of `FieldSet`: we don't care about the
Target
class, only that it has the fields we want
w

witty-crayon-22786

02/09/2022, 11:42 PM
yea. makes sense for renamed field lookups. ok, thanks
h

hundreds-father-404

02/09/2022, 11:44 PM
Not only that, but it's important you can write
black/rules.py
without knowing that
PythonSourceTarget
exists. We want to decouple target definitions from rule implementations because we can't predict what targets plugin authors will add
w

witty-crayon-22786

02/09/2022, 11:45 PM
sure. that still comes down to renamed field lookups i think… assuming that you always did
has_field(Sources)
before doing the field lookup. but yea, makes sense.
h

hundreds-father-404

02/09/2022, 11:46 PM
ah yeah, assuming you use
has_field()
. But then you have
.get()
to consider
w

witty-crayon-22786

02/09/2022, 11:46 PM
get
wouldn’t change i don’t think.
but not wanting to access by name makes sense.