[ty] Reject
type[Callable]special form (#23753)Summary
The typing spec says:
Any other special forms like Callable are not allowed as an argument to type.
We already reject
GenericandTypedDict. We should probably also rejectLiteral. But this PR addsCallable.
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
Ruff
Docs | Playground
An extremely fast Python linter and code formatter, written in Rust.
Linting the CPython codebase from scratch.
pippyproject.tomlsupportRuff aims to be orders of magnitude faster than alternative tools while integrating more functionality behind a single, common interface.
Ruff can be used to replace Flake8 (plus dozens of plugins), Black, isort, pydocstyle, pyupgrade, autoflake, and more, all while executing tens or hundreds of times faster than any individual tool.
Ruff is extremely actively developed and used in major open-source projects like:
…and many more.
Ruff is backed by Astral, the creators of uv and ty.
Read the launch post, or the original project announcement.
Testimonials
Sebastián Ramírez, creator of FastAPI:
Nick Schrock, founder of Elementl, co-creator of GraphQL:
Bryan Van de Ven, co-creator of Bokeh, original author of Conda:
Timothy Crosley, creator of isort:
Tim Abbott, lead developer of Zulip (also here):
Table of Contents
For more, see the documentation.
Getting Started
For more, see the documentation.
Installation
Ruff is available as
ruffon PyPI.Invoke Ruff directly with
uvx:Or install Ruff with
uv(recommended),pip, orpipx:Starting with version
0.5.0, Ruff can be installed with our standalone installers:You can also install Ruff via Homebrew, Conda, and with a variety of other package managers.
Usage
To run Ruff as a linter, try any of the following:
Or, to run Ruff as a formatter:
Ruff can also be used as a pre-commit hook via
ruff-pre-commit:Ruff can also be used as a VS Code extension or with various other editors.
Ruff can also be used as a GitHub Action via
ruff-action:Configuration
Ruff can be configured through a
pyproject.toml,ruff.toml, or.ruff.tomlfile (see: Configuration, or Settings for a complete list of all configuration options).If left unspecified, Ruff’s default configuration is equivalent to the following
ruff.tomlfile:Note that, in a
pyproject.toml, each section header should be prefixed withtool.ruff. For example,[lint]should be replaced with[tool.ruff.lint].Some configuration options can be provided via dedicated command-line arguments, such as those related to rule enablement and disablement, file discovery, and logging level:
The remaining configuration options can be provided through a catch-all
--configargument:To opt in to the latest lint rules, formatter style changes, interface updates, and more, enable preview mode by setting
preview = truein your configuration file or passing--previewon the command line. Preview mode enables a collection of unstable features that may change prior to stabilization.See
ruff helpfor more on Ruff’s top-level commands, orruff help checkandruff help formatfor more on the linting and formatting commands, respectively.Rules
Ruff supports over 900 lint rules, many of which are inspired by popular tools like Flake8, isort, pyupgrade, and others. Regardless of the rule’s origin, Ruff re-implements every rule in Rust as a first-party feature.
By default, Ruff enables Flake8’s
Frules, along with a subset of theErules, omitting any stylistic rules that overlap with the use of a formatter, likeruff formator Black.If you’re just getting started with Ruff, the default rule set is a great place to start: it catches a wide variety of common errors (like unused imports) with zero configuration.
In preview, Ruff enables an expanded set of default rules that includes rules from the
B,UP, andRUFcategories, as well as many more. If you give the new defaults a try, feel free to leave feedback in the GitHub discussion, where you can also find the new rule set listed in full.Beyond the defaults, Ruff re-implements some of the most popular Flake8 plugins and related code quality tools, including:
For a complete enumeration of the supported rules, see Rules.
Contributing
Contributions are welcome and highly appreciated. To get started, check out the contributing guidelines.
You can also join us on Discord.
Support
Having trouble? Check out the existing issues on GitHub, or feel free to open a new one.
You can also ask for help on Discord.
Acknowledgements
Ruff’s linter draws on both the APIs and implementation details of many other tools in the Python ecosystem, especially Flake8, Pyflakes, pycodestyle, pydocstyle, pyupgrade, and isort.
In some cases, Ruff includes a “direct” Rust port of the corresponding tool. We’re grateful to the maintainers of these tools for their work, and for all the value they’ve provided to the Python community.
Ruff’s formatter is built on a fork of Rome’s
rome_formatter, and again draws on both API and implementation details from Rome, Prettier, and Black.Ruff’s import resolver is based on the import resolution algorithm from Pyright.
Ruff is also influenced by a number of tools outside the Python ecosystem, like Clippy and ESLint.
Ruff is the beneficiary of a large number of contributors.
Ruff is released under the MIT license.
Who’s Using Ruff?
Ruff is used by a number of major open-source projects and companies, including:
Show Your Support
If you’re using Ruff, consider adding the Ruff badge to your project’s
README.md:…or
README.rst:…or, as HTML:
License
This repository is licensed under the MIT License