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

careful-address-89803

08/18/2022, 1:07 AM
out-there theoretical question, but could Pants handle a Generic rule? example: instead of subclassing
ExportPythonToolSentinel
we could have
Copy code
Tool = TypeVar("Tool", bound=ExportablePythonTool)  # ExportablePythonTool doesn't exist yet

class ExportPythonToolSentinel(Generic(Tool)):
    ...

@rule
def generic_export(_: ExportPythonToolSentinel[Tool], tool: Tool):
    ...
I'm not too familiar with the inner working of Python's type hint system and Pant's interaction with it. For example, I don't know if the references to
Tool
in the
generic_export
have to be the same. It seems kindof related to UnionRule?
h

happy-kitchen-89482

08/20/2022, 2:56 PM
@hundreds-father-404 ccing you so this doesn’t get lost in the scrollback
h

hundreds-father-404

08/22/2022, 5:00 PM
generally, rule signatures can't be complex like
List[str]
or
Optional[str]
. They have to a be a single
type()
. That's because the rule graph goes from types to types, and we store the information in Rust of the Python
type
c

careful-address-89803

08/22/2022, 6:02 PM
Oh, that makes sense, thanks! I wonder if I can get something off the ground with python crimes overriding
__getitem__
to return unique types.
h

hundreds-father-404

08/22/2022, 8:42 PM
Experimentation is definitely welcome on how to make the Rules API more ergonomic!