diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 60e52b3..8a604e2 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/claude-code-marketplace.json", "name": "heph-marketplace", - "version": "0.1.12", + "version": "0.1.13", "description": "Claude Code plugins for the heph build system, co-located with the docs.", "owner": { "name": "hephbuild", diff --git a/plugins/heph-expert/.claude-plugin/plugin.json b/plugins/heph-expert/.claude-plugin/plugin.json index 69d6838..2c7cb7b 100644 --- a/plugins/heph-expert/.claude-plugin/plugin.json +++ b/plugins/heph-expert/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/claude-code-plugin.json", "name": "heph-expert", - "version": "0.1.12", + "version": "0.1.13", "description": "Expert assistance for the heph build system: author BUILD files, debug caching and sandbox issues, wire up CI, and explain the target graph.", "author": { "name": "hephbuild" diff --git a/plugins/heph-expert/skills/heph/references/plugins.md b/plugins/heph-expert/skills/heph/references/plugins.md index e6a1a5e..6e6a255 100644 --- a/plugins/heph-expert/skills/heph/references/plugins.md +++ b/plugins/heph-expert/skills/heph/references/plugins.md @@ -154,7 +154,13 @@ parameters that forward to `target()`. `heph.types..Kwargs` (e.g. `heph.types.bash.Kwargs`, `heph.types.oci.image.Kwargs`; registered drivers only) types a wrapper's `**kwargs` per key: `target()`'s fields minus `driver` plus the driver's fields, closed (unknown key = type error), every key optional -and `None`-accepting; checked by lint and at evaluation. A file is checked only by the package whose directory +and `None`-accepting; checked by lint and at evaluation. Starlark's `typing` +namespace is a global in every BUILD file (`typing.Callable`, `typing.Any`, +`typing.Iterable`, `typing.Never`): `fn: typing.Callable[[str], bool]` types a +function parameter — lint checks the passed function's signature, evaluation +only that it is a function; bare `typing.Callable` / `typing.Any` satisfy +`requireTypeAnnotations` and are not checked further. `heph.types.Callable` / +`heph.types.Any` fail pointing at `typing.`. A file is checked only by the package whose directory holds it — name shared helpers `*.BUILD`. A user target with a check's name shadows it; `heph validate` fails on that. Full page: . diff --git a/website/docs/guides/checking-build-files.md b/website/docs/guides/checking-build-files.md index 0313159..ced5ec4 100644 --- a/website/docs/guides/checking-build-files.md +++ b/website/docs/guides/checking-build-files.md @@ -96,6 +96,32 @@ def lib(deps: heph.types.Deps = []): ... # accepts one address or a map Only `build-lint-check` checks inferred types. Evaluation checks annotations alone, so it accepts any argument for a parameter typed only by its default. +### Functions and `Any` + +Every BUILD file has the `typing` namespace: `typing.Callable`, `typing.Any`, +`typing.Iterable` and `typing.Never`. A parameter that takes a function names +the function's parameter types and return type: + +```python title="defs.BUILD" +def apply(fn: typing.Callable[[str], str], x: str) -> str: + return fn(x) + +def keep(xs: list[str], filter: list[str] | typing.Callable[[str], bool]) -> list[str]: + ... +``` + +`build-lint-check` checks a function passed there against that signature: +`apply(_len, "s")`, with `def _len(s: str) -> int`, reports: + +```text +type-error: Expected type `typing.Callable[[str], str]` but got `def(s: str) -> int` +``` + +Evaluation checks only that the argument is a function. Bare `typing.Callable` +takes any function and `typing.Any` takes any value; both satisfy +[`requireTypeAnnotations`](#requiring-type-annotations), and neither is +checked any further. + ### Allowing `None` A parameter takes `None` only when its annotation says `| None`, or when it is @@ -130,7 +156,9 @@ def lib(name: str, deps: heph.types.Deps = None, labels: heph.types.Labels = Non A field alias widens with its field and never narrows. `transitive` and `approval` have no alias; a driver's own fields are typed by its [`Kwargs`](#driver-kwargs). An unknown name such as `heph.types.Nope` fails -before evaluation and lists the known aliases and driver namespaces. In the +before evaluation and lists the known aliases and driver namespaces. +`heph.types.Callable`, `heph.types.Any` and the other `typing` names fail +pointing at `typing.` (see [Functions and `Any`](#functions-and-any)). In the editor, `heph.types.` completes the aliases, then the driver namespaces, and each alias shows its expansion on hover. diff --git a/website/docs/plugins/buildfile.md b/website/docs/plugins/buildfile.md index 62addbf..01f7836 100644 --- a/website/docs/plugins/buildfile.md +++ b/website/docs/plugins/buildfile.md @@ -136,6 +136,7 @@ The plugin exposes a fixed set of builtins: | `provider_state(provider, **kwargs)` | — | Hand package-level state to a provider. | | `heph.core` | namespace | Host platform info and current package. See [below](#hephcore--host-platform). | | `heph.types` | namespace | Type aliases for `target()` fields, to annotate wrapper `def`s. See [`heph.types`](/docs/guides/checking-build-files#hephtypes). | +| `typing` | namespace | `typing.Callable`, `typing.Any`, `typing.Iterable`, `typing.Never`, to annotate `def` parameters. See [Functions and `Any`](/docs/guides/checking-build-files#functions-and-any). | `file()` and `glob()` resolve to [filesystem](./fs.md) addresses; `query()` resolves to a [query](./query.md) address. All three drop straight into a