An extremely fast Python type checker and language server, written in Rust.
Warning
ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
ty is in active development, and we're working hard to make it stable and feature-complete.
uv tool install tyor add ty to your project:
uv add --dev ty
# With pip.
pip install tyAfter installing ty, you can check that ty is available by running the ty command:
ty
An extremely fast Python type checker.
Usage: ty <COMMAND>
...You should see a help menu listing the available commands.
For detailed information about command-line options, see the CLI documentation.
ty checkty can be integrated with various editors and IDEs to provide a seamless development experience. This section provides instructions on how to set up ty with your editor and configure it to your liking.
Install the ty extension from the VS Code Marketplace.
For more documentation on the ty extension, refer to the extension's README.
ty can be used with any editor that supports the language server protocol. To start the language server, run ty server. Refer to your editor's documentation
to learn how to connect to an LSP server.
Suppression comments allow you to silence specific instances of ty violations in your code, be they false positives or permissible violations.
Note
To disable a rule entirely, set its severity to ignore in your ty.toml or pyproject.toml or disable it using the --ignore CLI argument.
To suppress a violation inline add a # ty: ignore[rule] comment at the end of the line:
a = 10 + "test" # ty: ignore[unsupported-operator]Multiline violations can be suppressed by adding the comment at the end of the violation's first or last line:
def add_three(a: int, b: int, c: int): ...
add_three( # ty: ignore[missing-argument]
3,
2
)or when adding the suppression to the last line:
add_three(
3,
2
) # ty: ignore[missing-argument]To suppress multiple violations on the same line, list all rule names and separate them with a comma:
add_three("one", 5) # ty: ignore[missing-argument, invalid-argument-type]The comma separated list of rule names ([rule1, rule2]) is optional. We recommend to always suppress specific error codes to avoid accidental suppression of other errors.
ty supports the type: ignore comment format introduced with PEP 484. ty handles them similarly to ty: ignore comments, but it suppresses all violations on that line, even when using type: ignore[code].
# Ignore all typing errors on the next line
add_three("one", 5) # type: ignorety reports unused ty: ignore and type: ignore comments if the rule unused-ignore-comment is enabled. unused-ignore-comment violations
can only be suppressed using ty: ignore[unused-ignore-comment]. They can't be suppressed using ty: ignore (without a rule code) or a type: ignore comment.
ty supports the @no_type_check decorator to suppress all violations inside a function.
from typing import no_type_check
def add_three(a: int, b: int, c: int):
a + b + c
@no_type_check
def main():
add_three(3, 4)Decorating a class with @no_type_check isn't supported.
ty supports persistent configuration files at both the project- and user-level.
Specifically, ty will search for a pyproject.toml or ty.toml file in the current directory, or in the nearest parent directory.
If a pyproject.toml file is found, ty will read configuration from the [tool.ty] table. For example, to ignore the index-out-of-bounds rule, add the following to a pyproject.toml:
pyproject.toml:
[tool.ty.rules]
index-out-of-bounds = "ignore"(If there is no tool.ty table, the pyproject.toml file will be ignored, and ty will continue searching in the directory hierarchy.)
ty will also search for ty.toml files, which follow an identical structure, but omit the [tool.ty] prefix. For example:
ty.toml:
[rules]
index-out-of-bounds = "ignore"Note
ty.toml files take precedence over pyproject.toml files, so if both ty.toml and pyproject.toml files are present in a directory, configuration will be read from ty.toml, and the [tool.ty] section in the accompanying pyproject.toml will be ignored.
ty will also discover user-level configuration at ~/.config/ty/ty.toml (or $XDG_CONFIG_HOME/ty/ty.toml) on macOS and Linux, or %APPDATA%\ty\ty.toml on Windows. User-level configuration must use the ty.toml format, rather than the pyproject.toml format, as a pyproject.toml is intended to define a Python project.
If project- and user-level configuration files are found, the settings will be merged, with project-level configuration taking precedence over the user-level configuration.
For example, if a string, number, or boolean is present in both the project- and user-level configuration tables, the project-level value will be used, and the user-level value will be ignored. If an array is present in both tables, the arrays will be merged, with the project-level settings appearing later in the merged array.
Settings provided via command line take precedence over persistent configuration.
See the settings reference for an enumeration of the available settings.
ty defines and respects the following environment variables:
If set, ty will use this value as the log level for its --verbose output. Accepts any filter compatible with the tracing_subscriber crate. For example:
TY_LOG=uv=debugis the equivalent of-vvto the command lineTY_LOG=tracewill enable all trace-level logging.
See the tracing documentation for more.
Specifies an upper limit for the number of tasks ty is allowed to run in parallel. For example, how many files should be checked in parallel.
This isn’t the same as a thread limit. ty may spawn additional threads when necessary, e.g. to watch for file system changes or a dedicated UI thread.
ty also reads the following externally defined environment variables:
Specifies an upper limit for the number of threads ty uses when performing work in parallel. Equivalent to TY_MAX_PARALLELISM.
Used to detect an activated virtual environment.
Path to user-level configuration directory on Unix systems.
0if no violations with severityerroror higher were found.1if any violations with severityerrorwere found.2if ty terminates abnormally due to invalid CLI options.101if ty terminates abnormally due to an internal error.
ty supports two command line arguments that change how exit codes work:
--exit-zero: ty will exit with0even if violations were found.--error-on-warning: ty will exit with1if it finds any violations with severitywarningor higher.
If you have questions or want to report a bug, please open an issue in this repository.
Development of this project takes place in the Ruff repository
at this time. Please open pull requests there for changes
to anything in the ruff submodule (which includes all of the Rust source code).
See the contributing guide for more details.
ty is licensed under the MIT license (LICENSE or https://opensource.org/licenses/MIT).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in ty by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.