> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# @aspect_rules_lint//lint:ty.bzl

> Bazel rules_lint Ty integration: lint_ty_aspect to run the Ty Python type checker as a Bazel aspect across py_binary, py_library, and py_test rules.

<Callout icon="book">
  Documentation for [@aspect\_rules\_lint@v2.3.0](https://registry.bazel.build/modules/aspect_rules_lint/2.3.0) -- <Icon icon="github" iconType="brands" /> [View source](https://github.com/aspect-build/rules_lint/blob/v2.3.0/lint/ty.bzl)
</Callout>

API for declaring a Ty lint aspect that visits py\_`binary`, `library`, `test` rules.

Typical usage:

Ty is provided as a built-in tool by rules\_lint. To use the built-in version,
create the linter aspect, typically in `tools/lint/linters.bzl`:

```python theme={null}
load("@aspect_rules_lint//lint:ty.bzl", "lint_ty_aspect")

ty = lint_ty_aspect(
    binary = Label("@aspect_rules_lint//lint:ty_bin"),
    config = Label("//:ty.toml"),
)
```

## Function: `ty_action`

Run ty as an action under Bazel.

ty supports persistent configuration files at both the project- and user-level
as documented here: [https://docs.astral.sh/ty/configuration/](https://docs.astral.sh/ty/configuration/)

Note: all config files are passed to the action.
This means that a change to any config file invalidates the action cache entries for ALL
ty actions.

### Parameters

<ParamField body="ctx" type="unknown" required>
  Bazel Rule or Aspect evaluation context
</ParamField>

<ParamField body="executable" type="unknown" required>
  label of the ty program
</ParamField>

<ParamField body="srcs" type="unknown" required>
  python files to be linted
</ParamField>

<ParamField body="transitive_srcs" type="unknown" required>
  depset of transitive Python sources from dependencies
</ParamField>

<ParamField body="config" type="unknown" required>
  labels of ty config files (pyproject.toml, ty.toml)
</ParamField>

<ParamField body="stdout" type="unknown" required>
  output file of linter results to generate
</ParamField>

<ParamField body="exit_code" type="unknown" default={`None`}>
  output file to write the exit code.
  If None, then fail the build when ty exits non-zero.
  [https://docs.astral.sh/ty/reference/exit-codes/](https://docs.astral.sh/ty/reference/exit-codes/)
</ParamField>

<ParamField body="env" type="unknown" default={`{}`}>
  environment variables for ty
</ParamField>

<ParamField body="extra_search_paths" type="unknown" default={`[]`}>
  list of paths to add as --extra-search-path for third-party module resolution
</ParamField>

<ParamField body="color" type="unknown" default={`True`}>
  whether to enable color output (--color always) or disable it (--color never)
</ParamField>

## Function: `lint_ty_aspect`

A factory function to create a linter aspect.

Attrs:
binary: a ty executable
configs: ty config file(s) (`pyproject.toml`, `ty.toml`)
rule\_kinds: which [kinds](https://bazel.build/query/language#kind) of rules should be visited by the aspect
filegroup\_tags: filegroups tagged with these tags will be visited by the aspect in addition to Python rule kinds

### Parameters

<ParamField body="binary" type="unknown" required />

<ParamField body="config" type="unknown" required />

<ParamField body="rule_kinds" type="unknown" default={`["py_binary", "py_library", "py_test"]`} />

<ParamField body="filegroup_tags" type="unknown" default={`["python", "lint-with-ty"]`} />
