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

aloof-angle-91616

06/28/2019, 11:25 PM
and if it is dynamic you can always just assign to the
__doc__
attr
h

hundreds-father-404

06/28/2019, 11:26 PM
Would prefer avoiding this as much as possible. Didn’t realize there’s a difference between descriptions for live objects vs static rule graph. For static rule graph, agreed that it does not need to allow dynamic descriptions
a

aloof-angle-91616

06/28/2019, 11:27 PM
i don’t think we should be using the doc attr for describing specific instances though? i’ve only seen doc for descriptions of classes and methods
👍 1
i’m referring to dynamically generating unions in a meta programming sort of sense
h

hundreds-breakfast-49010

06/28/2019, 11:28 PM
I don't know which of the things is happening here
just that the
TargetType
union has no description and that's what I've been testing this against
also the rust-level print formatting (which calls
pretty_print
) wants to print the name of this union as just "type"
I'm not sure where that's coming from
a

aloof-angle-91616

06/28/2019, 11:30 PM
if you look at the decorator that’s how the return value is constructed — via the
type()
constructor
didn’t realize it would return anything for the docstring
yeah
pretty_print()
just uses the type's
__name__
it calls
extern_type_to_str
you could do
externs::project_str(val, "__doc__")
it looks like the
@union
decorator drops the docstring
w

witty-crayon-22786

06/28/2019, 11:35 PM
@hundreds-breakfast-49010: hm rather than
TargetType
you mean
TestTarget
, right?
h

hundreds-breakfast-49010

06/28/2019, 11:35 PM
ah yeah
TestTarget
as defined there
a

aloof-angle-91616

06/28/2019, 11:36 PM
Copy code
diff --git a/src/python/pants/engine/rules.py b/src/python/pants/engine/rules.py
index 8d44412e4..f3f49225b 100644
--- a/src/python/pants/engine/rules.py
+++ b/src/python/pants/engine/rules.py
@@ -301,6 +301,7 @@ def union(cls):
   # TODO: Check that the union base type is used as a tag and nothing else (e.g. no attributes)!
   assert isinstance(cls, type)
   return type(cls.__name__, (cls,), {
+    '__doc__': cls.__doc__,
     '_is_union': True,
   })
should work
or perhaps
functools.wraps()
still works there, but i'm not sure if that's kosher
h

hundreds-breakfast-49010

06/28/2019, 11:37 PM
what's functool.wraps() do?
functool is part of the python std lib now right?
a

aloof-angle-91616

06/28/2019, 11:37 PM
yes!
this feature was stdlib in py2 too i think it's just better in py3
functools.wraps()
forwards the docstring of a wrapped function to the function returned by a decorator
with some quick testing it appears to yell at you if you use it on a class
so manually forwarding
__doc__
seems fine for now
h

hundreds-breakfast-49010

06/28/2019, 11:43 PM
ah ok
a

aloof-angle-91616

06/28/2019, 11:44 PM
does that make sense?
h

hundreds-breakfast-49010

06/28/2019, 11:47 PM
it makes sense but doesn't seem to work when I try it
I wonder if the problem is
TypeId(c.to_id(type(input_type)))
in
extern_get_function_for
w

witty-crayon-22786

06/28/2019, 11:49 PM
yea, probably.
Er...
I will not figure this out on my phone. Sorry.
h

hundreds-breakfast-49010

06/28/2019, 11:50 PM
no worries
w

witty-crayon-22786

06/28/2019, 11:51 PM
Did you mean "`get_union_for`"...?
ah yeah
extern_get_union_for
in the python
w

witty-crayon-22786

06/28/2019, 11:52 PM
I'll comment there. That's more convoluted than it needs to be
If you're trying to check whether someone used a union in a Get, then the thing you're trying to check is just whether something is a union
So I think you might be operating on the wrong type from the Get
h

hundreds-breakfast-49010

06/28/2019, 11:59 PM
so declared_subject isn't the right thing to be checking?
w

witty-crayon-22786

06/29/2019, 12:19 AM
On my phone... unknown. Look at the position the union type is in in the example on the ticket (the middle position, iirc)
a

aloof-angle-91616

06/29/2019, 12:23 AM
it makes sense but doesn't seem to work when I try it
not working how?
h

hundreds-breakfast-49010

06/29/2019, 12:30 AM
manually forwarding the doc string in
union