so could I write an `@rule` that has a signature `...
# development
h
so could I write an
@rule
that has a signature
Tuple[X]
, and then use that?
a
yes, but we recommend using
Collection.of
h
NB:
Tuple[X]
!=
Tuple[X, ...]
h
what's the difference?
h
Tuple[X]
== tuple of 1 element of type X
Tuple[X, ...]
== tuple of n elements of type X
h
so I'd write the rule
@rule\ndef my_rule(x: Collection.of(WhateverType)) -> OutputType:...
and then use it like
x = yield Get(OutputType, WhateverType, (a, b, c,))
?
a
the type has to be saved to a variable -- see
src/python/pants/engine/build_files.py
for how it's used
CollectionOfWhatever = Collection.of(WhateverType)
h
ah okay
w
but also, remember our discussion about `Collection.of`: it doesn't add any useful information to the type
so we probably ought to use less of it.
a
ah ok
the thing about
Tuple[...]
as @hundreds-father-404 was saying is the type ascription
w
that's on me... need to improve the docs there maybe.
well, my point applies to Tuple/Collection/List/anything
a
because a collection of X is a
Tuple[X, X, X, X, X, ...]
yes
w
k
a
we just need some way to represent collections
definitely agree with your point in general
w
the gist of the comment on the ticket is "make a newtype", maybe extending from
Collection.of
i see the general point about Tuple though... that's unfortunate. is there a
Tuple[*X]
syntax? varargs?
a
great question
h
it's pretty easy to make a newtype that wraps a tuple of the things you wanted to include in a novel rule
but that adds a little bit of friction
a
does it? i always felt like that was a really good thing, to name everything with its own struct when possible
not trying to say i'm right, that is just my personal emotional response
feels nice to have names for things
w
@hundreds-breakfast-49010: what is the actual usecase involved here?
h
I wanted to write this rule in this PR: https://github.com/pantsbuild/pants/pull/8369/commits/8af08d8ef28ec8526757bc1c06e7f14d317a7f21#diff-7acfea499dbc0e147308fc0681d40184R29 as taking as its input a native python tuple of
PythonTargetAdaptor
I ended up creating a newtype for it
w
@hundreds-breakfast-49010: should that just be a private function?
or are you actually trying to allow for it to be reused more generally?
h
yeah it's an
@rule
so it's meant to be generally available
w
hm. k
yea, there is some amount of cost in extracting a
@rule
when compared to using a private function.
and that will probably drive how granular they are.
...which is a good thing, i think.
a
agreed^