total aside related to `FieldSet`… could `Target` ...
# development
w
total aside related to `FieldSet`… could
Target
use the same field-access mechanism?
…as an alternative to `target[Field]`…?
h
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
you can only have one value per alias though.
h
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
yea. makes sense for renamed field lookups. ok, thanks
h
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
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
ah yeah, assuming you use
has_field()
. But then you have
.get()
to consider
w
get
wouldn’t change i don’t think.
but not wanting to access by name makes sense.