pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.19k stars 613 forks source link

Export a `Rules` type for use in backends `rules` registration methods #21125

Open kaos opened 3 days ago

kaos commented 3 days ago
          Should we consider exporting a `Rules` type, making this more ergonomic, and also makes it easier in the future to add/adjust this interface with less code impact?
from pants.engine.rules import Rules

def rules() -> Rules:
  return ( ... )

# pants.engine.rules

Rules = TypeAlias[Iterable[Rule | UnionRule]]

_Originally posted by @kaos in https://github.com/pantsbuild/pants/pull/21124#discussion_r1663685655_

cognifloyd commented 3 days ago

Any other types we should include? Like QueryRule?

Rules = TypeAlias[Iterable[Rule | UnionRule | QueryRule]]
kaos commented 2 days ago

Any other types we should include? Like QueryRule?

Rules = TypeAlias[Iterable[Rule | UnionRule | QueryRule]]

That's not needed, as the QueryRule satisfies the Rule Protocol: https://github.com/pantsbuild/pants/blob/50a4e75b69321f3a2d3cb110433144c7f586ae38/src/python/pants/engine/rules.py#L408-L417 https://github.com/pantsbuild/pants/blob/50a4e75b69321f3a2d3cb110433144c7f586ae38/src/python/pants/engine/rules.py#L484-L492