pytest.warns expects to receive an expected warning as its first argument. If omitted, the pytest.warns call will fail at runtime. Ruff takes this rule from flake8-pytest-style. It is in preview.
- Code
PT029- Message
Set the expected warning in `pytest.warns()`
pytest.warns(Warning) will catch any Warning and may catch warnings that are unrelated to the code under test. To avoid this, pytest.warns should be called with a match parameter. The warning names that require a match parameter can be configured via the lint.flake8-pytest-style.warns-require-match-for and lint.flake8-pytest-style.warns-extend-require-match-for settings. Ruff takes this rule from flake8-pytest-style and made it stable in 0.12.0.
- Code
PT030- Message
`pytest.warns({})` is too broad, set the `match` parameter or use a more specific warning
When pytest.warns is used as a context manager and contains multiple statements, it can lead to the test passing when it should instead fail. Ruff takes this rule from flake8-pytest-style and made it stable in 0.12.0.
- Code
PT031- Message
`pytest.warns()` block should contain a single simple statement
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.resolve() can improve readability over the os.path module's counterparts (e.g., os.path.abspath()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH100- Message
`os.path.abspath()` should be replaced by `Path.resolve()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.chmod() can improve readability over the os module's counterparts (e.g., os.chmod()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH101- Message
`os.chmod()` should be replaced by `Path.chmod()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.mkdir() can improve readability over the os module's counterparts (e.g., os.mkdir()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH102- Message
`os.mkdir()` should be replaced by `Path.mkdir()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.mkdir(parents=True) can improve readability over the os module's counterparts (e.g., os.makedirs(). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH103- Message
`os.makedirs()` should be replaced by `Path.mkdir(parents=True)`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.rename() can improve readability over the os module's counterparts (e.g., os.rename()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH104- Message
`os.rename()` should be replaced by `Path.rename()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.replace() can improve readability over the os module's counterparts (e.g., os.replace()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH105- Message
`os.replace()` should be replaced by `Path.replace()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.rmdir() can improve readability over the os module's counterparts (e.g., os.rmdir()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH106- Message
`os.rmdir()` should be replaced by `Path.rmdir()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.unlink() can improve readability over the os module's counterparts (e.g., os.remove()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH107- Message
`os.remove()` should be replaced by `Path.unlink()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.unlink() can improve readability over the os module's counterparts (e.g., os.unlink()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH108- Message
`os.unlink()` should be replaced by `Path.unlink()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.cwd() can improve readability over the os module's counterparts (e.g., os.getcwd()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH109- Message
`os.getcwd()` should be replaced by `Path.cwd()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.exists() can improve readability over the os.path module's counterparts (e.g., os.path.exists()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH110- Message
`os.path.exists()` should be replaced by `Path.exists()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.expanduser() can improve readability over the os.path module's counterparts (e.g., as os.path.expanduser()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH111- Message
`os.path.expanduser()` should be replaced by `Path.expanduser()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.is_dir() can improve readability over the os.path module's counterparts (e.g., os.path.isdir()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH112- Message
`os.path.isdir()` should be replaced by `Path.is_dir()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.is_file() can improve readability over the os.path module's counterparts (e.g., os.path.isfile()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH113- Message
`os.path.isfile()` should be replaced by `Path.is_file()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.is_symlink() can improve readability over the os.path module's counterparts (e.g., os.path.islink()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH114- Message
`os.path.islink()` should be replaced by `Path.is_symlink()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.readlink() can improve readability over the os module's counterparts (e.g., os.readlink()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH115- Message
`os.readlink()` should be replaced by `Path.readlink()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using Path object methods such as Path.stat() can improve readability over the os module's counterparts (e.g., os.path.stat()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH116- Message
`os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.is_absolute() can improve readability over the os.path module's counterparts (e.g., as os.path.isabs()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH117- Message
`os.path.isabs()` should be replaced by `Path.is_absolute()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.joinpath() or the / operator can improve readability over the os.path module's counterparts (e.g., os.path.join()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH118- Message
`os.{}.join()` should be replaced by `Path` with `/` operator- Message
`os.{}.join()` should be replaced by `Path.joinpath()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.name can improve readability over the os.path module's counterparts (e.g., os.path.basename()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH119- Message
`os.path.basename()` should be replaced by `Path.name`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.parent can improve readability over the os.path module's counterparts (e.g., os.path.dirname()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH120- Message
`os.path.dirname()` should be replaced by `Path.parent`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.samefile() can improve readability over the os.path module's counterparts (e.g., os.path.samefile()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH121- Message
`os.path.samefile()` should be replaced by `Path.samefile()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. When possible, using Path object methods such as Path.suffix and Path.stem can improve readability over the os.path module's counterparts (e.g., os.path.splitext()). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH122- Message
`os.path.splitext()` should be replaced by `Path.suffix`, `Path.stem`, and `Path.parent`
pathlib offers a high-level API for path manipulation. When possible, using Path object methods such as Path.open() can improve readability over the open builtin. Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH123- Message
`open()` should be replaced by `Path.open()`
The py.path library is in maintenance mode. Instead, prefer the standard library's pathlib module, or third-party modules like path (formerly py.path). Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.231.
- Code
PTH124- Message
`py.path` is in maintenance mode, use `pathlib` instead
The Path() constructor defaults to the current directory, so passing it in explicitly (as ".") is unnecessary. Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.279.
- Code
PTH201- Message
Do not pass the current directory explicitly to `Path`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.279.
- Code
PTH202- Message
`os.path.getsize` should be replaced by `Path.stat().st_size`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.279.
- Code
PTH203- Message
`os.path.getatime` should be replaced by `Path.stat().st_atime`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.279.
- Code
PTH204- Message
`os.path.getmtime` should be replaced by `Path.stat().st_mtime`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.path. Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.279.
- Code
PTH205- Message
`os.path.getctime` should be replaced by `Path.stat().st_ctime`
The pathlib module in the standard library should be used for path manipulation. It provides a high-level API with the functionality needed for common operations on Path objects. Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.281.
- Code
PTH206- Message
Replace `.split(os.sep)` with `Path.parts`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os and glob. Ruff takes this rule from flake8-use-pathlib and made it stable in v0.0.281.
- Code
PTH207- Message
Replace `{}` with `Path.glob` or `Path.rglob`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os. When possible, using pathlib's Path.iterdir() can improve readability over os.listdir(). Ruff takes this rule from flake8-use-pathlib and made it stable in 0.10.0.
- Code
PTH208- Message
Use `pathlib.Path.iterdir()` instead.
Path.with_suffix() will raise an error at runtime if the given suffix is not prefixed with a dot or, in versions prior to Python 3.14, if it is a single dot ".". Ruff takes this rule from flake8-use-pathlib and made it stable in 0.10.0.
- Code
PTH210- Message
Invalid suffix passed to `.with_suffix()`- Message
Dotless suffix passed to `.with_suffix()`
pathlib offers a high-level API for path manipulation, as compared to the lower-level API offered by os.symlink. Ruff takes this rule from flake8-use-pathlib and made it stable in 0.13.0.
- Code
PTH211- Message
`os.symlink` should be replaced by `Path.symlink_to`
Prefixing type parameters with _ avoids accidentally exposing names internal to the stub. Ruff takes this rule from flake8-pyi and made it stable in v0.0.245.
- Code
PYI001- Message
Name of private `{}` must start with `_`
Type checkers understand simple conditionals to express variations between different Python versions and platforms. However, complex tests may not be understood by a type checker, leading to incorrect inferences when they analyze your code. Ruff takes this rule from flake8-pyi and made it stable in v0.0.276.
- Code
PYI002- Message
`if` test must be a simple comparison against `sys.platform` or `sys.version_info`
Stub files support simple conditionals to test for differences in Python versions using sys.version_info. However, there are a number of common mistakes involving sys.version_info comparisons that should be avoided. For example, comparing against a string can lead to unexpected behavior. Ruff takes this rule from flake8-pyi and made it stable in v0.0.276.
- Code
PYI003- Message
Unrecognized `sys.version_info` check
Stub files support simple conditionals to test for differences in Python versions and platforms. However, type checkers only understand a limited subset of these conditionals. In particular, type checkers don't support patch versions (e.g., Python 3.8.3), only major and minor versions (e.g., Python 3.8). Therefore, version checks in stubs should only use the major and minor versions. Ruff takes this rule from flake8-pyi and made it stable in v0.0.276.
- Code
PYI004- Message
Version comparison must use only major and minor version
Stub files support simple conditionals to test for differences in Python versions and platforms. When comparing against sys.version_info, avoid comparing against tuples of the wrong length, which can lead to unexpected behavior. Ruff takes this rule from flake8-pyi and made it stable in v0.0.276.
- Code
PYI005- Message
Version comparison must be against a length-{} tuple
All other comparators, such as >, <=, and ==, are banned. Comparing sys.version_info with == or <= has unexpected behavior and can lead to bugs. Ruff takes this rule from flake8-pyi and made it stable in v0.0.254.
- Code
PYI006- Message
Use `<` or `>=` for `sys.version_info` comparisons
Platform checks should be simple string comparisons. Some sys.platform checks are too complex for type checkers to understand, and thus result in incorrect inferences by these tools. sys.platform checks should be simple string comparisons, like if sys.platform == "linux". Ruff takes this rule from flake8-pyi and made it stable in v0.0.246.
- Code
PYI007- Message
Unrecognized `sys.platform` check
If a sys.platform check compares to a platform name outside of a small set of known platforms (e.g. "linux", "win32", etc.), it's likely a typo or a platform name that is not recognized by type checkers. Ruff takes this rule from flake8-pyi and made it stable in v0.0.246.
- Code
PYI008- Message
Unrecognized platform `{}`
For stylistic consistency, ... should always be used rather than pass in stub files. Ruff takes this rule from flake8-pyi and made it stable in v0.0.253.
- Code
PYI009- Message
Empty body should contain `...`, not `pass`
Stub files are never executed at runtime; they should be thought of as "data files" for type checkers or IDEs. Function bodies are redundant for this purpose. Ruff takes this rule from flake8-pyi and made it stable in v0.0.253.
- Code
PYI010- Message
Function body must contain only `...`
Stub (.pyi) files exist as "data files" for static analysis tools, and are not evaluated at runtime. While simple default values may be useful for some tools that consume stubs, such as IDEs, they are ignored by type checkers. Ruff takes this rule from flake8-pyi and made it stable in v0.0.253.
- Code
PYI011- Message
Only simple default values allowed for typed arguments
The pass statement is always unnecessary in non-empty class bodies in stubs. Ruff takes this rule from flake8-pyi and made it stable in v0.0.260.
- Code
PYI012- Message
Class body must not contain `pass`
An ellipsis in a class body is only necessary if the class body is otherwise empty. If the class body is non-empty, then the ellipsis is redundant. Ruff takes this rule from flake8-pyi and made it stable in v0.0.270.
- Code
PYI013- Message
Non-empty class body must not contain `...`
Stub (.pyi) files exist to define type hints, and are not evaluated at runtime. As such, function arguments in stub files should not have default values, as they are ignored by type checkers. Ruff takes this rule from flake8-pyi and made it stable in v0.0.253.
- Code
PYI014- Message
Only simple default values allowed for arguments
Stub (.pyi) files exist to define type hints, and are not evaluated at runtime. As such, assignments in stub files should not include values, as they are ignored by type checkers. Ruff takes this rule from flake8-pyi and made it stable in v0.0.260.
- Code
PYI015- Message
Only simple default values allowed for assignments
Duplicate union members are redundant and should be removed. Ruff takes this rule from flake8-pyi and made it stable in v0.0.262.
- Code
PYI016- Message
Duplicate union member `{}`
In general, stub files should be thought of as "data files" for a type checker, and are not intended to be executed. As such, it's useful to enforce that only a subset of Python syntax is allowed in a stub file, to ensure that everything in the stub is unambiguous for the type checker. Ruff takes this rule from flake8-pyi and made it stable in v0.0.279.
- Code
PYI017- Message
Stubs should not contain assignments to attributes or multiple targets
A private TypeVar that is defined but not used is likely a mistake. It should either be used, made public, or removed to avoid confusion. A type variable is considered "private" if its name starts with an underscore. Ruff takes this rule from flake8-pyi and made it stable in v0.0.281.
- Code
PYI018- Message
Private {} `{}` is never used
While the semantics are often identical, using Self is more intuitive and succinct (per PEP 673) than a custom TypeVar. For example, the use of Self will typically allow for the omission of type parameters on the self and cls arguments. Ruff takes this rule from flake8-pyi and made it stable in v0.0.283.
- Code
PYI019- Message
Use `Self` instead of custom TypeVar `{}`
Stub files natively support forward references in all contexts, as stubs are never executed at runtime. (They should be thought of as "data files" for type checkers and IDEs.) As such, quotes are never required for type annotations in stub files, and should be omitted. Ruff takes this rule from flake8-pyi and made it stable in v0.0.265.
- Code
PYI020- Message
Quoted annotations should not be included in stubs
Stub files should omit docstrings, as they're intended to provide type hints, rather than documentation. Ruff takes this rule from flake8-pyi and made it stable in v0.0.253.
- Code
PYI021- Message
Docstrings should not be included in stubs
typing.NamedTuple is the "typed version" of collections.namedtuple. Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI024- Message
Use `typing.NamedTuple` instead of `collections.namedtuple`
The Set type in collections.abc is an abstract base class for set-like types. It is easily confused with, and not equivalent to, the set builtin. Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI025- Message
Use `from collections.abc import Set as AbstractSet` to avoid confusion with the `set` builtin
In Python, a type alias is defined by assigning a type to a variable (e.g., Vector = listfloat). Ruff takes this rule from flake8-pyi and made it stable in v0.0.279.
- Code
PYI026- Message
Use `{}.TypeAlias` for type alias, e.g., `{}: TypeAlias = {}`
Defining __str__ or __repr__ in a stub is almost always redundant, as the signatures are almost always identical to those of the default equivalent, object.__str__ and object.__repr__, respectively. Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI029- Message
Defining `{}` in a stub is almost always redundant
Literal"foo", 42 has identical semantics to Literal"foo" | Literal42, but is clearer and more concise. Ruff takes this rule from flake8-pyi and made it stable in v0.0.278.
- Code
PYI030- Message
Multiple literal members in a union. Use a single literal, e.g. `Literal[{}]`
The Python documentation recommends the use of object to "indicate that a value could be any type in a typesafe manner". Any, on the other hand, should be seen as an "escape hatch when you need to mix dynamically and statically typed code". Since using Any allows you to write highly unsafe code, you should generally only use Any when the semantics of your code would otherwise be inexpressible to the type checker. Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI032- Message
Prefer `object` to `Any` for the second parameter to `{}`
Type comments are a soft-deprecated form of type annotation. They are unsupported by some modern type checkers, including ty and Pyrefly, and are only necessary when supporting end-of-life Python versions such as 3.5 or older. They are never necessary in stub files, which are not executed at runtime. Ruff takes this rule from flake8-pyi and made it stable in v0.0.254.
- Code
PYI033- Message
Don't use type comments
If methods that generally return self at runtime are annotated with a fixed return type, and the class is subclassed, type checkers will not be able to infer the correct return type. Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI034- Message
`__new__` methods usually return `self` at runtime- Message
`{}` methods in classes like `{}` usually return `self` at runtime
Special variables like __all__ have the same semantics in stub files as they do in Python modules, and so should be consistent with their runtime counterparts. Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI035- Message
`{}` in a stub file must have a value, as it has the same semantics as `{}` at runtime
Improperly annotated __exit__ and __aexit__ methods can cause unexpected behavior when interacting with type checkers. Ruff takes this rule from flake8-pyi and made it stable in v0.0.279.
- Code
PYI036- Message
Star-args in `{}` should be annotated with `object`- Message
If there are no star-args, `{}` should have at least 3 non-keyword-only args (excluding `self`)- Message
All arguments after the first four in `{}` must have a default value- Message
All keyword-only arguments in `{}` must have a default value- Message
The first argument in `{}` should be annotated with `object` or `type[BaseException] | None`- Message
The second argument in `{}` should be annotated with `object` or `BaseException | None`- Message
The third argument in `{}` should be annotated with `object` or `types.TracebackType | None`- Message
Annotations for a three-argument `{}` overload (excluding `self`) should either be `None, None, None` or `type[BaseException], BaseException, types.TracebackType`
The typing specification states: Ruff takes this rule from flake8-pyi and made it stable in v0.0.279.
- Code
PYI041- Message
Use `{}` instead of `{} | {}`
It's conventional to use the CamelCase naming convention for type aliases, to distinguish them from other variables. Ruff takes this rule from flake8-pyi and made it stable in v0.0.265.
- Code
PYI042- Message
Type alias `{}` should be CamelCase
It's conventional to use the 'T' suffix for type variables; the use of such a suffix implies that the object is a TypeVar. Ruff takes this rule from flake8-pyi and made it stable in v0.0.265.
- Code
PYI043- Message
Private type alias `{}` should not be suffixed with `T` (the `T` suffix implies that an object is a `TypeVar`)
Stub files natively support forward references in all contexts, as stubs are never executed at runtime. (They should be thought of as "data files" for type checkers.) As such, the from __future__ import annotations import statement has no effect and should be omitted. Ruff takes this rule from flake8-pyi and made it stable in v0.0.273.
- Code
PYI044- Message
`from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
__iter__ methods should always should return an Iterator of some kind, not an Iterable. Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI045- Message
`__aiter__` methods should return an `AsyncIterator`, not an `AsyncIterable`- Message
`__iter__` methods should return an `Iterator`, not an `Iterable`
A private typing.Protocol that is defined but not used is likely a mistake. It should either be used, made public, or removed to avoid confusion. Ruff takes this rule from flake8-pyi and made it stable in v0.0.281.
- Code
PYI046- Message
Private protocol `{}` is never used
A private type alias that is defined but not used is likely a mistake. It should either be used, made public, or removed to avoid confusion. Ruff takes this rule from flake8-pyi and made it stable in v0.0.281.
- Code
PYI047- Message
Private TypeAlias `{}` is never used
Stub files are never executed, and are only intended to define type hints. As such, functions in stub files should not contain functional code, and should instead contain only a single statement (e.g., ...). Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI048- Message
Function body must contain exactly one statement
A private typing.TypedDict that is defined but not used is likely a mistake. It should either be used, made public, or removed to avoid confusion. Ruff takes this rule from flake8-pyi and made it stable in v0.0.281.
- Code
PYI049- Message
Private TypedDict `{}` is never used
Prefer Never over NoReturn for parameter annotations. Never has a clearer name in these contexts, since it makes little sense to talk about a parameter annotation "not returning". Ruff takes this rule from flake8-pyi and made it stable in v0.0.272.
- Code
PYI050- Message
Prefer `{}.Never` over `NoReturn` for argument annotations
Using a Literal type in a union with its builtin supertype is redundant, as the supertype will be strictly more general than the Literal type. For example, Literal"A" | str is equivalent to str, and Literal1 | int is equivalent to int, as str and int are the supertypes of "A" and 1 respectively. Ruff takes this rule from flake8-pyi and made it stable in v0.0.283.
- Code
PYI051- Message
`Literal[{}]` is redundant in a union with `{}`- Message
`Literal` is redundant in a union with `{}`
Stub files exist to provide type hints, and are never executed. As such, all assignments in stub files should be annotated with a type. Ruff takes this rule from flake8-pyi and made it stable in v0.0.269.
- Code
PYI052- Message
Need type annotation for `{}`
If a function or variable has a default value where the string or bytes representation is greater than 50 characters long, it is likely to be an implementation detail or a constant that varies depending on the system you're running on. Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI053- Message
String and bytes literals longer than 50 characters are not permitted
If a function has a default value where the literal representation is greater than 10 characters, the value is likely to be an implementation detail or a constant that varies depending on the system you're running on. Ruff takes this rule from flake8-pyi and made it stable in v0.0.271.
- Code
PYI054- Message
Numeric literals with a string representation longer than ten characters are not permitted
typeT | S has identical semantics to typeT | typeS in a type annotation, but is cleaner and more concise. Ruff takes this rule from flake8-pyi and made it stable in v0.0.283.
- Code
PYI055- Message
Multiple `type` members in a union. Combine them into one, e.g., `type[{}]`.
Different type checkers have varying levels of support for calling these methods on __all__. Instead, use the += operator to add items to __all__, which is known to be supported by all major type checkers. Ruff takes this rule from flake8-pyi and made it stable in v0.0.281.
- Code
PYI056- Message
Calling `.{}()` on `__all__` may not be supported by all type checkers (use `+=` instead)
ByteString has been deprecated since Python 3.9 and will be removed in Python 3.17. The Python documentation recommends using either collections.abc.Buffer (or the typing_extensions backport on Python <3.12) or a union like bytes | bytearray | memoryview instead. Ruff takes this rule from flake8-pyi and made it stable in 0.6.0.
- Code
PYI057- Message
Do not use `{}.ByteString`, which has unclear semantics and is deprecated
Using (Async)Iterator for these methods is simpler and more elegant. More importantly, it also reflects the fact that the precise kind of iterator returned from an __iter__ method is usually an implementation detail that could change at any time. Type annotations help define a contract for a function; implementation details should not leak into that contract. Ruff takes this rule from flake8-pyi and made it stable in v0.2.0.
- Code
PYI058- Message
Use `{}` as the return value for simple `{}` methods
If Generic[] is not the final class in the bases tuple, unexpected behaviour can occur at runtime (See this CPython issue for an example). Ruff takes this rule from flake8-pyi and made it stable in 0.13.0.
- Code
PYI059- Message
`Generic[]` should always be the last base class
While LiteralNone is a valid type annotation, it is semantically equivalent to None. Prefer None over LiteralNone for both consistency and readability. Ruff takes this rule from flake8-pyi and made it stable in 0.13.0.
- Code
PYI061- Message
Use `None` rather than `Literal[None]`- Message
Use `Optional[Literal[...]]` rather than `Literal[None, ...]`- Message
Use `Literal[...] | None` rather than `Literal[None, ...]`
Duplicate literal members are redundant and should be removed. Ruff takes this rule from flake8-pyi and made it stable in 0.6.0.
- Code
PYI062- Message
Duplicate literal member `{}`
Historically, PEP 484 recommended prefixing parameter names with double underscores (__) to indicate to a type checker that they were positional-only. However, PEP 570 (introduced in Python 3.8) introduced dedicated syntax for positional-only arguments. If a forward slash (/) is present in a function signature on Python 3.8+, all parameters prior to the slash are interpreted as positional-only. Ruff takes this rule from flake8-pyi and made it stable in 0.8.0.
- Code
PYI063- Message
Use PEP 570 syntax for positional-only parameters
All constant variables annotated as Final are understood as implicitly having Literal types by a type checker. As such, a FinalLiteral[...] annotation can often be replaced with a bare Final, annotation, which will have the same meaning to the type checker while being more concise and more readable. Ruff takes this rule from flake8-pyi and made it stable in 0.8.0.
- Code
PYI064- Message
`Final[Literal[{}]]` can be replaced with a bare `Final`
As a convention, branches that correspond to newer Python versions should come first. This makes it easier to understand the desired behavior, which typically corresponds to the latest Python versions. Ruff takes this rule from flake8-pyi and made it stable in 0.8.0.
- Code
PYI066- Message
Put branches for newer Python versions first when branching on `sys.version_info` comparisons
Consistency is good. Use either single or double quotes for inline strings, but be consistent. Ruff takes this rule from flake8-quotes and made it stable in v0.0.88.
- Code
Q000- Message
Single quotes found but double quotes preferred- Message
Double quotes found but single quotes preferred
Consistency is good. Use either single or double quotes for multiline strings, but be consistent. Ruff takes this rule from flake8-quotes and made it stable in v0.0.88.
- Code
Q001- Message
Single quote multiline found but double quotes preferred- Message
Double quote multiline found but single quotes preferred
Consistency is good. Use either single or double quotes for docstring strings, but be consistent. Ruff takes this rule from flake8-quotes and made it stable in v0.0.88.
- Code
Q002- Message
Single quote docstring found but double quotes preferred- Message
Double quote docstring found but single quotes preferred
It's preferable to avoid escaped quotes in strings. By changing the outer quote style, you can avoid escaping inner quotes. Ruff takes this rule from flake8-quotes and made it stable in v0.0.88.
- Code
Q003- Message
Change outer quotes to avoid escaping inner quotes
If a string contains an escaped quote that doesn't match the quote character used for the string, it's unnecessary and can be removed. Ruff takes this rule from flake8-quotes and made it stable in v0.2.0.
- Code
Q004- Message
Unnecessary escape on inner quote character
Used when comparing an object to a literal, which is usually what you do not want to do, since you can compare to a different literal than what was expected altogether. pylint calls it literal-comparison.
- Code
R0123- Severity
- refactor
- Message
In '{}', use '{}' when comparing constant literals not '{}' ('{}')
Used when something is compared against itself. pylint calls it comparison-with-itself.
- Code
R0124- Severity
- refactor
- Message
Redundant comparison - {}
When two literals are compared with each other the result is a constant. Using the constant directly is both easier to read and more performant. Initializing 'True' and 'False' this way is not required since Python 2.3. pylint calls it comparison-of-constants.
- Code
R0133- Severity
- refactor
- Message
Comparison between constants: "{} {} {}" has a constant value
Used when a class method is defined without using the decorator syntax. pylint calls it no-classmethod-decorator.
- Code
R0202- Severity
- refactor
- Message
Consider using a decorator instead of calling classmethod
Used when a static method is defined without using the decorator syntax. pylint calls it no-staticmethod-decorator.
- Code
R0203- Severity
- refactor
- Message
Consider using a decorator instead of calling staticmethod
Used when a class inherit from object, which under python3 is implicit, hence can be safely removed from bases. pylint calls it useless-object-inheritance.
- Code
R0205- Severity
- refactor
- Message
Class {} inherits from object, can be safely removed from bases in python3
Used when we detect that a property also has parameters, which are useless, given that properties cannot be called with additional arguments. pylint calls it property-with-parameters.
- Code
R0206- Severity
- refactor
- Message
Cannot have defined parameters for properties
Used when a cyclic import between two or more modules is detected. pylint calls it cyclic-import.
- Code
R0401- Severity
- refactor
- Message
Cyclic import ({})
Emitted when a submodule of a package is imported and aliased with the same name, e.g., instead of import concurrent.futures as futures use from concurrent import futures. pylint calls it consider-using-from-import.
- Code
R0402- Severity
- refactor
- Message
Use 'from {} import {}' instead
Indicates that a set of similar lines has been detected among multiple file. This usually means that the code should be refactored to avoid this duplication. pylint calls it duplicate-code.
- Code
R0801- Severity
- refactor
- Message
Similar lines in {} files
Used when class has too many parent classes, try to reduce this to get a simpler (and so easier to use) class. pylint calls it too-many-ancestors.
- Code
R0901- Severity
- refactor
- Message
Too many ancestors ({}/{})
Used when class has too many instance attributes, try to reduce this to get a simpler (and so easier to use) class. pylint calls it too-many-instance-attributes.
- Code
R0902- Severity
- refactor
- Message
Too many instance attributes ({}/{})
Used when class has too few public methods, so be sure it's really worth it. pylint calls it too-few-public-methods.
- Code
R0903- Severity
- refactor
- Message
Too few public methods ({}/{})
Used when class has too many public methods, try to reduce this to get a simpler (and so easier to use) class. pylint calls it too-many-public-methods.
- Code
R0904- Severity
- refactor
- Message
Too many public methods ({}/{})
Used when a function or method has too many return statement, making it hard to follow. pylint calls it too-many-return-statements.
- Code
R0911- Severity
- refactor
- Message
Too many return statements ({}/{})
Used when a function or method has too many branches, making it hard to follow. pylint calls it too-many-branches.
- Code
R0912- Severity
- refactor
- Message
Too many branches ({}/{})
Used when a function or method takes too many arguments. pylint calls it too-many-arguments.
- Code
R0913- Severity
- refactor
- Message
Too many arguments ({}/{})
Used when a function or method has too many local variables. pylint calls it too-many-locals.
- Code
R0914- Severity
- refactor
- Message
Too many local variables ({}/{})
Used when a function or method has too many statements. You should then split it in smaller functions / methods. pylint calls it too-many-statements.
- Code
R0915- Severity
- refactor
- Message
Too many statements ({}/{})
Used when an if statement contains too many boolean expressions. pylint calls it too-many-boolean-expressions.
- Code
R0916- Severity
- refactor
- Message
Too many boolean expressions in if statement ({}/{})
Used when a function has too many positional arguments. pylint calls it too-many-positional-arguments.
- Code
R0917- Severity
- refactor
- Message
Too many positional arguments ({}/{})
Used when multiple consecutive isinstance calls can be merged into one. pylint calls it consider-merging-isinstance.
- Code
R1701- Severity
- refactor
- Message
Consider merging these isinstance calls to isinstance({}, ({}))
Used when a function or a method has too many nested blocks. This makes the code less understandable and maintainable. pylint calls it too-many-nested-blocks.
- Code
R1702- Severity
- refactor
- Message
Too many nested blocks ({}/{})
Used when an if statement can be replaced with 'bool(test)'. pylint calls it simplifiable-if-statement.
- Code
R1703- Severity
- refactor
- Message
The if statement can be replaced with {}
Used when a local name is redefining an argument, which might suggest a potential error. This is taken in account only for a handful of name binding operations, such as for iteration, with statement assignment and exception handler assignment. pylint calls it redefined-argument-from-local.
- Code
R1704- Severity
- refactor
- Message
Redefining argument with the local name {}
Used in order to highlight an unnecessary block of code following an if, or a try/except containing a return statement. As such, it will warn when it encounters an else following a chain of ifs, all of them containing a return statement. pylint calls it no-else-return.
- Code
R1705- Severity
- refactor
- Message
Unnecessary "{}" after "return", {}
Used when one of known pre-python 2.5 ternary syntax is used. pylint calls it consider-using-ternary.
- Code
R1706- Severity
- refactor
- Message
Consider using ternary ({})
In Python, a tuple is actually created by the comma symbol, not by the parentheses. Unfortunately, one can actually create a tuple by misplacing a trailing comma, which can lead to potential weird bugs in your code. You should always use parentheses explicitly for creating a tuple. pylint calls it trailing-comma-tuple.
- Code
R1707- Severity
- refactor
- Message
Disallow trailing comma tuple
According to PEP479, the raise of StopIteration to end the loop of a generator may lead to hard to find bugs. This PEP specify that raise StopIteration has to be replaced by a simple return statement. pylint calls it stop-iteration-return.
- Code
R1708- Severity
- refactor
- Message
Do not raise StopIteration in generator, use return statement instead
Emitted when redundant pre-python 2.5 ternary syntax is used. pylint calls it simplify-boolean-expression.
- Code
R1709- Severity
- refactor
- Message
Boolean expression may be simplified to {}
According to PEP8, if any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None, and an explicit return statement should be present at the end of the function (if reachable). pylint calls it inconsistent-return-statements.
- Code
R1710- Severity
- refactor
- Message
Either all return statements in a function should return an expression, or none of them should.
Emitted when a single "return" or "return None" statement is found at the end of function or method definition. This statement can safely be removed because Python will implicitly return None. pylint calls it useless-return.
- Code
R1711- Severity
- refactor
- Message
Useless return at end of function or method
You do not have to use a temporary variable in order to swap variables. Using "tuple unpacking" to directly swap variables makes the intention more clear. pylint calls it consider-swap-variables.
- Code
R1712- Severity
- refactor
- Message
Consider using tuple unpacking for swapping variables
Using str.join(sequence) is faster, uses less memory and increases readability compared to for-loop iteration. pylint calls it consider-using-join.
- Code
R1713- Severity
- refactor
- Message
Consider using str.join(sequence) for concatenating strings from an iterable
To check if a variable is equal to one of many values, combine the values into a set or tuple and check if the variable is contained "in" it instead of checking for equality against each of the values. This is faster and less verbose. pylint calls it consider-using-in.
- Code
R1714- Severity
- refactor
- Message
Consider merging these comparisons with 'in' by using '{} {}in ({})'. Use a set instead if elements are hashable.
Using the builtin dict.get for getting a value from a dictionary if a key is present or a default if not, is simpler and considered more idiomatic, although sometimes a bit slower. pylint calls it consider-using-get.
- Code
R1715- Severity
- refactor
- Message
Consider using dict.get for getting values from a dict if a key is present or a default if not
This message is emitted when pylint encounters boolean operation like "a < b and b < c", suggesting instead to refactor it to "a < b < c". pylint calls it chained-comparison.
- Code
R1716- Severity
- refactor
- Message
Simplify chained comparison between the operands: {}
Emitted when we detect the creation of a dictionary using the dict() callable and a transient list. Although there is nothing syntactically wrong with this code, it is hard to read and can be simplified to a dict comprehension. Also it is faster since you don't need to create another transient list. pylint calls it consider-using-dict-comprehension.
- Code
R1717- Severity
- refactor
- Message
Consider using a dictionary comprehension
Although there is nothing syntactically wrong with this code, it is hard to read and can be simplified to a set comprehension. Also it is faster since you don't need to create another transient list. pylint calls it consider-using-set-comprehension.
- Code
R1718- Severity
- refactor
- Message
Consider using a set comprehension
Used when an if expression can be replaced with 'bool(test)' or simply 'test' if the boolean cast is implicit. pylint calls it simplifiable-if-expression.
- Code
R1719- Severity
- refactor
- Message
The if expression can be replaced with {}
Used in order to highlight an unnecessary block of code following an if, or a try/except containing a raise statement. As such, it will warn when it encounters an else following a chain of ifs, all of them containing a raise statement. pylint calls it no-else-raise.
- Code
R1720- Severity
- refactor
- Message
Unnecessary "{}" after "raise", {}
Instead of using an identity comprehension, consider using the list, dict or set constructor. It is faster and simpler. pylint calls it unnecessary-comprehension.
- Code
R1721- Severity
- refactor
- Message
Unnecessary use of a comprehension, use {} instead.
Contrary to 'exit()' or 'quit()', 'sys.exit' does not rely on the site module being available (as the 'sys' module is always available). pylint calls it consider-using-sys-exit.
- Code
R1722- Severity
- refactor
- Message
Consider using 'sys.exit' instead
Used in order to highlight an unnecessary block of code following an if containing a break statement. As such, it will warn when it encounters an else following a chain of ifs, all of them containing a break statement. pylint calls it no-else-break.
- Code
R1723- Severity
- refactor
- Message
Unnecessary "{}" after "break", {}
Used in order to highlight an unnecessary block of code following an if containing a continue statement. As such, it will warn when it encounters an else following a chain of ifs, all of them containing a continue statement. pylint calls it no-else-continue.
- Code
R1724- Severity
- refactor
- Message
Unnecessary "{}" after "continue", {}
Emitted when calling the super() builtin with the current class and instance. On Python 3 these arguments are the default and they can be omitted. pylint calls it super-with-arguments.
- Code
R1725- Severity
- refactor
- Message
Consider using Python 3 style super() without arguments
Emitted when a boolean condition is able to be simplified. pylint calls it simplifiable-condition.
- Code
R1726- Severity
- refactor
- Message
Boolean condition "{}" may be simplified to "{}"
Emitted when a boolean condition can be simplified to a constant value. pylint calls it condition-evals-to-constant.
- Code
R1727- Severity
- refactor
- Message
Boolean condition '{}' will always evaluate to '{}'
If your container can be large using a generator will bring better performance. pylint calls it consider-using-generator.
- Code
R1728- Severity
- refactor
- Message
Consider using a generator instead '{}({})'
Comprehension inside of 'any', 'all', 'max', 'min' or 'sum' is unnecessary. A generator would be sufficient and faster. pylint calls it use-a-generator.
- Code
R1729- Severity
- refactor
- Message
Use a generator instead '{}({})'
Using the min builtin instead of a conditional improves readability and conciseness. pylint calls it consider-using-min-builtin.
- Code
R1730- Severity
- refactor
- Message
Consider using '{}' instead of unnecessary if block
Using the max builtin instead of a conditional improves readability and conciseness. pylint calls it consider-using-max-builtin.
- Code
R1731- Severity
- refactor
- Message
Consider using '{}' instead of unnecessary if block
Emitted if a resource-allocating assignment or call may be replaced by a 'with' block. By using 'with' the release of the allocated resources is ensured even in the case of an exception. pylint calls it consider-using-with.
- Code
R1732- Severity
- refactor
- Message
Consider using 'with' for resource-allocating operations
Emitted when iterating over the dictionary items (key-item pairs) and accessing the value by index lookup. The value can be accessed directly instead. pylint calls it unnecessary-dict-index-lookup.
- Code
R1733- Severity
- refactor
- Message
Unnecessary dictionary index lookup, use '{}' instead
Emitted when using list() to create an empty list instead of the literal []. The literal is faster as it avoids an additional function call. pylint calls it use-list-literal.
- Code
R1734- Severity
- refactor
- Message
Consider using [] instead of list()
Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call. pylint calls it use-dict-literal.
- Code
R1735- Severity
- refactor
- Message
Consider using '{}' instead of a call to 'dict'.
Emitted when iterating over an enumeration and accessing the value by index lookup. The value can be accessed directly instead. pylint calls it unnecessary-list-index-lookup.
- Code
R1736- Severity
- refactor
- Message
Unnecessary list index lookup, use '{}' instead
Yielding directly from the iterator is faster and arguably cleaner code than yielding each element one by one in the loop. pylint calls it use-yield-from.
- Code
R1737- Severity
- refactor
- Message
Use 'yield from' directly instead of yielding each element one by one
Emitted when the operands of a boolean condition form a cycle of weak inequalities (<= or >=). The condition is equivalent to checking that all the operands are equal. pylint calls it chained-comparison-all-equal.
- Code
R1738- Severity
- refactor
- Message
Simplify chained comparison cycle to equality between the operands: {}
Emitted when a boolean condition contains a chain of comparisons that is logically contradictory and can never be true (e.g. a > b and b > a). pylint calls it impossible-comparison.
- Code
R1739- Severity
- refactor
- Message
This comparison always evaluates to False
Match class patterns are faster if the name binding happens for the whole pattern and any lookup for __match_args__ can be avoided. pylint calls it match-class-bind-self.
- Code
R1905- Severity
- refactor
- Message
Use '{}() as {}' instead
Keyword attributes are more explicit and slightly faster since CPython can skip the __match_args__ lookup. pylint calls it match-class-positional-attributes.
- Code
R1906- Severity
- refactor
- Message
Use keyword attributes instead of positional ones ({})
If you use --warn-redundant-casts, mypy will generate an error if the source type of a cast is the same as the target type. mypy does not enable this error code by default. Use --enable-error-code redundant-cast to enable it.
- Code
redundant-cast- Severity
- error
If you use --enable-error-code redundant-expr, mypy generates an error if it thinks that an expression is redundant. mypy does not enable this error code by default. Use --enable-error-code redundant-expr to enable it.
- Code
redundant-expr- Severity
- error
If a method uses the Self type in the return type or the type of a non-self argument, there is no need to annotate the self argument explicitly. Such annotations are allowed by 673 but are redundant. mypy does not enable this error code by default. Use --enable-error-code redundant-self to enable it.
- Code
redundant-self- Severity
- error
Python implicitly assumes return None if an explicit return value is omitted. Therefore, explicitly returning None is redundant and should be avoided when it is the only possible return value across all code paths in a given function. Ruff takes this rule from flake8-return and made it stable in v0.0.154.
- Code
RET501- Message
Do not explicitly `return None` in function if it is the only possible return value
Including a return statement with no explicit value can cause confusion when other return statements in the function return non-None values. Python implicitly assumes return None if no other return value is present. Adding an explicit return None can make the code more readable by clarifying intent. Ruff takes this rule from flake8-return and made it stable in v0.0.154.
- Code
RET502- Message
Do not implicitly `return None` in function able to return non-`None` value
The lack of an explicit return statement at the end of a function that can return non-None values can cause confusion. Python implicitly returns None if no other return value is present. Adding an explicit return None can make the code more readable by clarifying intent. Ruff takes this rule from flake8-return and made it stable in v0.0.154.
- Code
RET503- Message
Missing explicit `return` at the end of function able to return non-`None` value
The variable assignment is not necessary, as the value can be returned directly. Ruff takes this rule from flake8-return and made it stable in v0.0.154.
- Code
RET504- Message
Unnecessary assignment to `{}` before `return` statement
The else statement is not needed as the return statement will always break out of the enclosing function. Removing the else will reduce nesting and make the code more readable. Ruff takes this rule from flake8-return and made it stable in v0.0.154.
- Code
RET505- Message
Unnecessary `{}` after `return` statement
The else statement is not needed as the raise statement will always break out of the current scope. Removing the else will reduce nesting and make the code more readable. Ruff takes this rule from flake8-return and made it stable in v0.0.154.
- Code
RET506- Message
Unnecessary `{}` after `raise` statement
The else statement is not needed, as the continue statement will always continue onto the next iteration of a loop. Removing the else will reduce nesting and make the code more readable. Ruff takes this rule from flake8-return and made it stable in v0.0.154.
- Code
RET507- Message
Unnecessary `{}` after `continue` statement
The else statement is not needed, as the break statement will always break out of the loop. Removing the else will reduce nesting and make the code more readable. Ruff takes this rule from flake8-return and made it stable in v0.0.154.
- Code
RET508- Message
Unnecessary `{}` after `break` statement
If a function has a non-None return type, mypy expects that the function always explicitly returns a value (or raises an exception). The function should not fall off the end of the function, since this is often a bug. mypy enables this error code by default.
- Code
return- Severity
- error
Mypy checks that the returned value is compatible with the type signature of the function. mypy enables this error code by default.
- Code
return-value- Severity
- error
If an exception is raised without any arguments, parentheses are not required, as the raise statement accepts either an exception instance or an exception class (which is then implicitly instantiated). Ruff takes this rule from flake8-raise and made it stable in v0.0.239.
- Code
RSE102- Message
Unnecessary parentheses on raised exception
Some Unicode characters are visually similar to ASCII characters, but have different code points. For example, GREEK CAPITAL LETTER ALPHA (U+0391) is visually similar, but not identical, to the ASCII character A. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.102.
- Code
RUF001- Message
String contains ambiguous {}. Did you mean {}?
Some Unicode characters are visually similar to ASCII characters, but have different code points. For example, GREEK CAPITAL LETTER ALPHA (U+0391) is visually similar, but not identical, to the ASCII character A. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.102.
- Code
RUF002- Message
Docstring contains ambiguous {}. Did you mean {}?
Some Unicode characters are visually similar to ASCII characters, but have different code points. For example, GREEK CAPITAL LETTER ALPHA (U+0391) is visually similar, but not identical, to the ASCII character A. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.108.
- Code
RUF003- Message
Comment contains ambiguous {}. Did you mean {}?
In Python, the + operator can be used to concatenate collections (e.g., x + y to concatenate the lists x and y). Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.227.
- Code
RUF005- Message
Consider `{}` instead of concatenation- Message
Consider iterable unpacking instead of concatenation
Per the asyncio documentation, the event loop only retains a weak reference to tasks. If the task returned by asyncio.create_task and asyncio.ensure_future is not stored in a variable, or a collection, or otherwise referenced, it may be garbage collected at any time. This can lead to unexpected and inconsistent behavior, as your tasks may or may not run to completion. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.247.
- Code
RUF006- Message
Store a reference to the return value of `{}.{}`
When iterating over successive pairs of elements, prefer itertools.pairwise() over zip(). Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.257.
- Code
RUF007- Message
Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs
Mutable default values share state across all instances of the dataclass. This can lead to bugs when the attributes are changed in one instance, as those changes will unexpectedly affect all other instances. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.262.
- Code
RUF008- Message
Do not use mutable default values for dataclass attributes
Function calls are only performed once, at definition time. The returned value is then reused by all instances of the dataclass. This can lead to unexpected behavior when the function call returns a mutable object, as changes to the object will be shared across all instances. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.262.
- Code
RUF009- Message
Do not perform function call `{}` in dataclass defaults- Message
Do not perform function call in dataclass defaults
f-strings support dedicated conversion flags for these types, which are more succinct and idiomatic. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.267.
- Code
RUF010- Message
Use explicit conversion flag
Using a static key (like a string literal) in a dictionary comprehension is usually a mistake, as it will result in a dictionary with only one key, despite the comprehension iterating over multiple values. Ruff takes this rule from Ruff-specific rules, and removed it.
- Code
RUF011- Message
Dictionary comprehension uses static key
Mutable default values share state across all instances of the class, while not being obvious. This can lead to bugs when the attributes are changed in one instance, as those changes will unexpectedly affect all other instances. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.273.
- Code
RUF012- Message
Mutable default value for class attribute
Implicit Optional is prohibited by PEP 484. It is confusing and inconsistent with the rest of the type system. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.273.
- Code
RUF013- Message
PEP 484 prohibits implicit `Optional`
Calling e.g. list(...) will create a new list of the entire collection, which can be very expensive for large collections. If you only need the first element of the collection, you can use next(...) or next(iter(...) to lazily fetch the first element. The same is true for the other constructs. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.278.
- Code
RUF015- Message
Prefer `next({})` over single element slice
Only integers or slices can be used as indices to these types. Using other types will result in a TypeError at runtime and a SyntaxWarning at import time. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.278.
- Code
RUF016- Message
Slice in indexed access to type `{}` uses type `{}` instead of an integer- Message
Indexed access to type `{}` uses type `{}` instead of an integer or slice
The use of sum() to flatten lists of lists is quadratic in the number of lists, as sum() creates a new list for each element in the summation. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.285.
- Code
RUF017- Message
Avoid quadratic list summation
Named assignment expressions (also known as "walrus operators") are used to assign a value to a variable as part of a larger expression. Ruff takes this rule from Ruff-specific rules and made it stable in v0.2.0.
- Code
RUF018- Message
Avoid assignment expressions in `assert` statements
When working with dictionaries, the get can be used to access a value without having to check if the dictionary contains the relevant key, returning None if the key is not present. Ruff takes this rule from Ruff-specific rules and made it stable in v0.2.0.
- Code
RUF019- Message
Unnecessary key check before dictionary access
typing.NoReturn and typing.Never are special types, used to indicate that a function never returns, or that a type has no values. Ruff takes this rule from Ruff-specific rules and made it stable in v0.2.0.
- Code
RUF020- Message
`{} | T` is equivalent to `T`- Message
`Union[{}, T]` is equivalent to `T`
and always binds more tightly than or when chaining the two together, but this can be hard to remember (and sometimes surprising). Adding parentheses in these situations can greatly improve code readability, with no change to semantics or performance. Ruff takes this rule from Ruff-specific rules and made it stable in 0.8.0.
- Code
RUF021- Message
Parenthesize `a and b` expressions when chaining `and` and `or` together, to make the precedence clear
Consistency is good. Use a common convention for __all__ to make your code more readable and idiomatic. Ruff takes this rule from Ruff-specific rules and made it stable in 0.8.0.
- Code
RUF022- Message
`__all__` is not sorted
Consistency is good. Use a common convention for this special variable to make your code more readable and idiomatic. Ruff takes this rule from Ruff-specific rules and made it stable in 0.8.0.
- Code
RUF023- Message
`{}.__slots__` is not sorted
All values in the dictionary created by the dict.fromkeys method refer to the same instance of the provided object. If that object is modified, all values are modified, which can lead to unexpected behavior. For example, if the empty list ([]) is provided as the default value, all values in the dictionary will use the same list; as such, appending to any one entry will append to all entries. Ruff takes this rule from Ruff-specific rules and made it stable in 0.5.0.
- Code
RUF024- Message
Do not pass mutable objects as values to `dict.fromkeys`
The defaultdict constructor accepts a callable as its first argument. For example, it's common to initialize a defaultdict with int or list via defaultdict(int) or defaultdict(list), to create a dictionary that returns 0 or [] respectively when a key is missing. Ruff takes this rule from Ruff-specific rules and made it stable in 0.5.0.
- Code
RUF026- Message
`default_factory` is a positional-only argument to `defaultdict`
Expressions inside curly braces are only evaluated if the string has an f prefix. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF027- Message
Possible f-string without an `f` prefix
Suppression comments that do not actually prevent formatting could cause unintended changes when the formatter is run. Ruff takes this rule from Ruff-specific rules and made it stable in 0.12.0.
- Code
RUF028- Message
This suppression comment is invalid because {}
Declaring a function async when it's not is usually a mistake, and will artificially limit the contexts where that function may be called. In some cases, labeling a function async is semantically meaningful. For example, an async test or callback may need to run in an async execution context, even if it only uses a ContextVar. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF029- Message
Function `{}` is declared `async`, but doesn't `await` or use `async` features.