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

hundreds-breakfast-49010

10/01/2019, 1:02 AM
so could I write an
@rule
that has a signature
Tuple[X]
, and then use that?
a

aloof-angle-91616

10/01/2019, 1:03 AM
yes, but we recommend using
Collection.of
h

hundreds-father-404

10/01/2019, 1:03 AM
NB:
Tuple[X]
!=
Tuple[X, ...]
h

hundreds-breakfast-49010

10/01/2019, 1:03 AM
what's the difference?
h

hundreds-father-404

10/01/2019, 1:03 AM
Tuple[X]
== tuple of 1 element of type X
Tuple[X, ...]
== tuple of n elements of type X
h

hundreds-breakfast-49010

10/01/2019, 1:03 AM
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

aloof-angle-91616

10/01/2019, 1:04 AM
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

hundreds-breakfast-49010

10/01/2019, 1:04 AM
ah okay
w

witty-crayon-22786

10/01/2019, 4:00 PM
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

aloof-angle-91616

10/01/2019, 4:01 PM
ah ok
the thing about
Tuple[...]
as @hundreds-father-404 was saying is the type ascription
w

witty-crayon-22786

10/01/2019, 4:02 PM
that's on me... need to improve the docs there maybe.
well, my point applies to Tuple/Collection/List/anything
a

aloof-angle-91616

10/01/2019, 4:02 PM
because a collection of X is a
Tuple[X, X, X, X, X, ...]
yes
w

witty-crayon-22786

10/01/2019, 4:03 PM
k
a

aloof-angle-91616

10/01/2019, 4:03 PM
we just need some way to represent collections
definitely agree with your point in general
w

witty-crayon-22786

10/01/2019, 4:05 PM
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

aloof-angle-91616

10/01/2019, 4:06 PM
great question
h

hundreds-breakfast-49010

10/01/2019, 5:17 PM
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

aloof-angle-91616

10/01/2019, 6:33 PM
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

witty-crayon-22786

10/01/2019, 6:34 PM
@hundreds-breakfast-49010: what is the actual usecase involved here?
h

hundreds-breakfast-49010

10/01/2019, 6:36 PM
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

witty-crayon-22786

10/01/2019, 6:40 PM
@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

hundreds-breakfast-49010

10/01/2019, 6:43 PM
yeah it's an
@rule
so it's meant to be generally available
w

witty-crayon-22786

10/01/2019, 6:47 PM
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

aloof-angle-91616

10/01/2019, 9:43 PM
agreed^