wide-midnight-78598
02/20/2025, 4:10 PM@rule
swide-midnight-78598
02/20/2025, 4:10 PMwide-midnight-78598
02/20/2025, 4:11 PMproud-dentist-22844
02/20/2025, 7:47 PM@rule
is very complex, so pycharm (and VSCode? It looks like your screenshot is of VSCode) have a hard time inferring the types. So, I end up looking up the rule and importing the rule's result to use in a type hint - at least while I'm developing. Sometimes, I then remove it to make mypy happy because the type checkers don't agree on inference logic.wide-midnight-78598
02/20/2025, 7:53 PMwide-midnight-78598
02/20/2025, 7:53 PMproud-dentist-22844
02/20/2025, 7:55 PMwide-midnight-78598
02/20/2025, 7:59 PMwide-midnight-78598
02/20/2025, 10:41 PMwide-midnight-78598
02/20/2025, 10:41 PMF = TypeVar('F', bound=Callable[..., Any])
@overload
def rule(func: F, /) -> F: ...
@overload
def rule(*, desc: str = "", level: LogLevel = LogLevel.DEBUG) -> Callable[[F], F]: ...
Sorta workswide-midnight-78598
02/21/2025, 1:06 AMproud-dentist-22844
02/21/2025, 1:22 AM@rule
that allows the function to be either sync or async.proud-dentist-22844
02/21/2025, 1:23 AMproud-dentist-22844
02/21/2025, 1:23 AMhappy-kitchen-89482
02/21/2025, 2:23 AMasync
is purely informational, since we’re not executing rules in a python event loophappy-kitchen-89482
02/21/2025, 2:23 AMasync
if it helps with typingwide-midnight-78598
02/21/2025, 7:55 AMwide-midnight-78598
02/21/2025, 1:46 PMtheBut, we still requireis purely informational,async
await
for call-by-name right? At the very least due to the trampoline back into rust code and using the tokio executor? Would that imply that not having async
is kinda technically incorrect?
Or does it just get wrapped and fired off as a co-routine regardless of whether it's considered a Python coroutine or notwide-midnight-78598
02/21/2025, 2:25 PMdef rule_decorator(func: SyncRuleT | AsyncRuleT, **kwargs) -> AsyncRuleT:
wide-midnight-78598
02/21/2025, 4:01 PMproud-dentist-22844
02/21/2025, 4:06 PMproud-dentist-22844
02/21/2025, 4:06 PMproud-dentist-22844
02/21/2025, 4:07 PMwide-midnight-78598
02/21/2025, 4:08 PMwide-midnight-78598
02/21/2025, 4:09 PMwide-midnight-78598
02/21/2025, 4:15 PMwide-midnight-78598
02/21/2025, 4:25 PMwide-midnight-78598
02/21/2025, 4:38 PMwide-midnight-78598
02/21/2025, 5:04 PM@rule(desc="Find targets from input specs", level=LogLevel.DEBUG, _masked_types=[EnvironmentName])
_masked_types: tuple[type, ...]
fails with No overload variant of "rule" matches argument type "list[type[EnvironmentName]]"
Do we particularly care that this is a tuple, per se? Or just any iterable (as it suggests downstream)? I can change the callsites to tuples, or just expand the typing to Iterable to fix this - but 🤷fast-nail-55400
02/21/2025, 5:11 PM_masked_types
was a thing until now.fast-nail-55400
02/21/2025, 5:12 PMmasked_types: tuple[type, ...] = tuple(kwargs.get("_masked_types", ()))
wide-midnight-78598
02/21/2025, 5:12 PMfast-nail-55400
02/21/2025, 5:12 PMIterable
is appropriate?wide-midnight-78598
02/21/2025, 5:12 PMfast-nail-55400
02/21/2025, 5:13 PMfast-nail-55400
02/21/2025, 5:13 PMwide-midnight-78598
02/21/2025, 5:14 PMfast-nail-55400
02/21/2025, 5:14 PMfast-nail-55400
02/21/2025, 5:15 PMfast-nail-55400
02/21/2025, 5:17 PMwide-midnight-78598
02/21/2025, 5:18 PMwide-midnight-78598
02/21/2025, 5:58 PMwide-midnight-78598
02/21/2025, 6:01 PMhappy-kitchen-89482
02/22/2025, 5:21 AM_masked_types
even ishappy-kitchen-89482
02/22/2025, 5:21 AMwide-midnight-78598
02/22/2025, 5:38 AMwide-midnight-78598
02/22/2025, 5:39 AMAllows callers to prevent the given list of types from being included in the identity of
a @rule
happy-kitchen-89482
02/23/2025, 5:15 PMwide-midnight-78598
02/23/2025, 5:39 PMwide-midnight-78598
02/23/2025, 5:40 PMEnvironmentName
- and I'm not in the know about Environment stuffwide-midnight-78598
02/23/2025, 5:40 PM⏺ pants.git/call-by-name-shell % rg _masked_types ⎇ call-by-name-shell*
src/python/pants/engine/rules.py
193: "_masked_types",
214: _masked_types: NotRequired[Iterable[type[Any]]]
252: masked_types: tuple[type, ...] = tuple(kwargs.get("_masked_types", ()))
src/python/pants/engine/internals/specs_rules.py
130:@rule(_masked_types=[EnvironmentName])
157:@rule(_masked_types=[EnvironmentName])
225:@rule(_masked_types=[EnvironmentName])
246:@rule(_masked_types=[EnvironmentName])
256:@rule(_masked_types=[EnvironmentName])
268:@rule(desc="Find targets from input specs", level=LogLevel.DEBUG, _masked_types=[EnvironmentName])
279:@rule(_masked_types=[EnvironmentName])
src/python/pants/engine/internals/graph.py
114:@rule(_masked_types=[EnvironmentName])
521:@rule(_masked_types=[EnvironmentName])
593:@rule(_masked_types=[EnvironmentName])
638:@rule(desc="Find all targets in the project", level=LogLevel.DEBUG, _masked_types=[EnvironmentName])
653: _masked_types=[EnvironmentName],
808:@rule(desc="Resolve transitive targets", level=LogLevel.DEBUG, _masked_types=[EnvironmentName])
881:@rule(_masked_types=[EnvironmentName])
886:@rule(desc="Resolve coarsened targets", level=LogLevel.DEBUG, _masked_types=[EnvironmentName])
1077:@rule(desc="Find which targets own certain files", _masked_types=[EnvironmentName])
1494:@rule(desc="Resolve direct dependencies of target", _masked_types=[EnvironmentName])
witty-crayon-22786
03/10/2025, 4:47 PMwitty-crayon-22786
03/10/2025, 4:49 PMpants dependencies
, etc depending on which environment you were running them in.
obviously the rest of the graph might change, but preventing it in the build graph "felt" like a good idea. who knows!witty-crayon-22786
03/10/2025, 4:50 PMwide-midnight-78598
03/10/2025, 4:51 PMwitty-crayon-22786
03/10/2025, 4:52 PMgraph.py
, and rendered using the introspection goals... dependencies
, list
, etc. the "graph graph" is the graph of rule invocationswitty-crayon-22786
03/10/2025, 4:53 PM