Skip to content

Commit 23684f6

Browse files
authored
agents(rules): add Starlark dict union and Pyrefly PackagePath conventions (bazel-contrib#4038)
Starlark supports the dictionary union operator (|), making skylib's dicts.add redundant. When using importlib.metadata in Python, f.locate() is typed as PathLike and lacks filesystem methods like .exists() and .is_file() under Pyrefly unless wrapped with pathlib.Path. Add rules instructing agents to prefer the dict union operator (|) over dicts.add in Starlark and to wrap f.locate() calls with pathlib.Path() in Python type-annotated code.
1 parent 9361a1a commit 23684f6

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎.agents/rules/python.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
link to its definition in the docstring.
1515

1616
## Type Checking & Annotations
17+
* **`importlib.metadata` `PackagePath`**: `f.locate()` is typed as `PathLike`.
18+
Wrap with `pathlib.Path(f.locate())` to call `.exists()`, `.is_file()`, etc.
1719
* **In-file disables vs target skipping**: Prefer `# pyrefly: ignore[<error-code>]`
1820
(e.g. `[missing-import]`) over `tags = ["no-pyrefly"]`.
1921
* **No blanket ignores**: NEVER use bare `# type: ignore` or literal

‎.agents/rules/starlark.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ globs: "*.bzl,BUILD,BUILD.bazel,*.bazel"
4141
`while` loops; iterate over fixed-size ranges or explicit collections.
4242

4343
## Code Style & Conventions
44+
* **Dict union (`|`)**: Use `|` instead of `dicts.add(...)` from
45+
`@bazel_skylib//lib:dicts.bzl` when merging dictionaries.
4446
* **Docstring Formatting Invariants**: Use triple-quoted strings for multi-line
4547
docstrings without trailing backslashes (`\`) for line continuation.
4648
* **No Bazel Copyright Headers**: Do not add Bazel copyright headers to new or

0 commit comments

Comments
 (0)