and if it is dynamic you can always just assign to...
# development
a
and if it is dynamic you can always just assign to the
__doc__
attr
h
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
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
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
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
@hundreds-breakfast-49010: hm rather than
TargetType
you mean
TestTarget
, right?
h
ah yeah
TestTarget
as defined there
a
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
what's functool.wraps() do?
functool is part of the python std lib now right?
a
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
ah ok
a
does that make sense?
h
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
yea, probably.
Er...
I will not figure this out on my phone. Sorry.
h
no worries
w
Did you mean "`get_union_for`"...?
ah yeah
extern_get_union_for
in the python
w
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
so declared_subject isn't the right thing to be checking?
w
On my phone... unknown. Look at the position the union type is in in the example on the ticket (the middle position, iirc)
a
it makes sense but doesn't seem to work when I try it
not working how?
h
manually forwarding the doc string in
union