I'm pretty sure I'm hitting a limitation here, but...
# plugins
h
I'm pretty sure I'm hitting a limitation here, but I guess it's worth a shot just asking I've got a rule that returns an instance of a subclass of a custom object (call it
Letter
) If I've got, say
A
and
B
, it seems to be impossible to create a rule, because it doesn't accept
TypeVar
return type The only "workaround" I found is to create a custom dataclass with a single property
letter
and then have that as the return value, but that's cumbersome because every time I use it I have to go
letter.letter.<my_attr>
Is there a better way?
f
You are likely hitting the limitation that the engine only looks at the exact type of the return type in assembling the rule graph. That is, the engine is type invariant.
And the workaround you used is a workaround used in many other places in the rules.
For example,
WrappedTarget
h
I see
Thanks for confirming that with an example from the official repo 🙂
👍 1
c
Not sure we want to advertise this, but there is a (undocumented) power-feature that may fit, depending on your situation.. https://github.com/pantsbuild/pants/pull/16929
(ah, I see they're marked as internal, so use is at ones own risk, I suppose.. 😬 )
h
Oh, wow... Looks quite funky.. But I'll take a look anyway Thanks
c
yea, guess it became more of a curiosity 😅