out-there theoretical question, but could Pants ha...
# development
c
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
@hundreds-father-404 ccing you so this doesn’t get lost in the scrollback
h
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
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
Experimentation is definitely welcome on how to make the Rules API more ergonomic!