bitter-ability-32190
09/20/2022, 12:47 AM@rule
that allows you to specify the param types in the decorator and it ignores the annotation.
Use-case is "inner" rules:
def rule_maker(a):
@rule(param_type_override={"foo": a.sometype})
def my_rule(foo: Foo) -> ...:
...
wide-midnight-78598
09/20/2022, 12:52 AMbitter-ability-32190
09/20/2022, 12:56 AMbitter-ability-32190
09/20/2022, 12:57 AMwide-midnight-78598
09/20/2022, 1:08 AMwide-midnight-78598
09/20/2022, 1:09 AMmypy
(or pyright
or whatever) treat this?bitter-ability-32190
09/20/2022, 1:11 AMbitter-ability-32190
09/20/2022, 1:15 AMwide-midnight-78598
09/20/2022, 1:19 AMmypy
or whatever end up using the override? Or would it still think Foo
is the type?wide-midnight-78598
09/20/2022, 1:22 AMmypy
had weird behaviour when it came to this, I think it was even in the FAQ (or that might have been mypyc
wide-midnight-78598
09/20/2022, 1:26 AMbitter-ability-32190
09/20/2022, 1:42 AMcareful-address-89803
09/20/2022, 3:44 AMdef rule_maker(a)
def my_rule(foo: Foo) -> Tout:
...
return = TaskRule(
output_type=Tout,
input_selectors=[a.sometype],
func=my_rule,
...
)
careful-address-89803
09/20/2022, 3:47 AM_make_rule
already does much of that. Pros: exists; Cons: no helpful validationcareful-address-89803
09/20/2022, 4:45 AMbitter-ability-32190
09/20/2022, 10:51 AMbitter-ability-32190
09/20/2022, 1:10 PMfrom __future__ import annotations
.bitter-ability-32190
09/20/2022, 1:10 PMhundreds-father-404
09/20/2022, 4:37 PMPants uses the type annotation of the param as a convenient way to get graph info. Nothing says that has to be where pants gets it fromFYI we used to have a much more verbose syntax in the early days of v2. I've forgotten what it was lol. Using type hints was a huge simplification, but you are correct that it need not come from there always
bitter-ability-32190
09/20/2022, 4:37 PMbitter-ability-32190
09/20/2022, 4:39 PMbitter-ability-32190
09/20/2022, 4:41 PMbitter-ability-32190
09/20/2022, 5:52 PM