Programming Search⌘K

Python lints, page 1 of 8

The lint rules of Python, with what each one finds. This page has 1,420 cards.

Checks for variable (and function) assignments that use the same names as builtins. A001

Reusing a builtin name for the name of a variable increases the difficulty of reading and maintaining the code, and can cause non-obvious errors, as readers may mistake the variable for the builtin and vice versa. Ruff takes this rule from flake8-builtins and made it stable in v0.0.48.

Code
A001
Message
Variable `{}` is shadowing a Python builtin

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for function arguments that use the same names as builtins. A002

Reusing a builtin name for the name of an argument increases the difficulty of reading and maintaining the code, and can cause non-obvious errors, as readers may mistake the argument for the builtin and vice versa. Ruff takes this rule from flake8-builtins and made it stable in v0.0.48.

Code
A002
Message
Function argument `{}` is shadowing a Python builtin

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for class attributes and methods that use the same names as Python builtins. A003

Reusing a builtin name for the name of an attribute increases the difficulty of reading and maintaining the code, and can cause non-obvious errors, as readers may mistake the attribute for the builtin and vice versa. Ruff takes this rule from flake8-builtins and made it stable in v0.0.48.

Code
A003
Message
Python builtin is shadowed by class attribute `{}` from {}
Message
Python builtin is shadowed by method `{}` from {}

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for modules that use the same names as Python standard-library modules. A005

Reusing a standard-library module name for the name of a module increases the difficulty of reading and maintaining the code, and can cause non-obvious errors. Readers may mistake the first-party module for the standard-library module and vice versa. Ruff takes this rule from flake8-builtins and made it stable in 0.9.0.

Code
A005
Message
Module `{}` shadows a Python standard-library module

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for lambda arguments that use the same names as Python builtins. A006

Reusing a builtin name for the name of a lambda argument increases the difficulty of reading and maintaining the code and can cause non-obvious errors. Readers may mistake the variable for the builtin, and vice versa. Ruff takes this rule from flake8-builtins and made it stable in 0.9.0.

Code
A006
Message
Lambda argument `{}` is shadowing a Python builtin

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for a DAG() class or @dag() decorator without an explicit schedule (or schedule_interval for Airflow 1) parameter. AIR002

The default value of the schedule parameter on Airflow 2 and schedule_interval on Airflow 1 is timedelta(days=1), which is almost never what a user is looking for. Airflow 3 changed the default value to None, and would break existing Dags using the implicit default. Ruff takes this rule from Airflow and made it stable in 0.13.0.

Code
AIR002
Message
`DAG` or `@dag` should have an explicit `schedule` argument

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for Variable.get() calls outside of Airflow task execution context (i.e., outside @task-decorated functions and operator execute() methods). AIR003

Calling Variable.get() at module level or in operator constructor arguments causes a database query every time the Dag file is parsed by the scheduler. This can degrade Dag parsing performance and, in some cases, cause the Dag file to time out before it is fully parsed. Ruff takes this rule from Airflow. It is in preview.

Code
AIR003
Message
`Variable.get()` outside of a task

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for branching logic that could be replaced with a short-circuit pattern, either via @task.branch decorated functions or BranchPythonOperator callables. AIR004

When a branch function has at least two return statements and exactly one of them returns a non-empty list, the function is effectively acting as a short-circuit operator. Using @task.short_circuit or ShortCircuitOperator is simpler and more readable in such cases. Ruff takes this rule from Airflow. It is in preview.

Code
AIR004
Message
`@task.branch` can be replaced with `@task.short_circuit`
Message
`BranchPythonOperator` can be replaced with `ShortCircuitOperator`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for Airflow operator keyword arguments that use a Jinja template string containing a single xcom_pull call to retrieve another task's output. AIR201

Using {{ ti.xcom_pull(task_ids='some_task') }} as a string template to access the output of an upstream task is less readable and more error-prone than using the .output attribute on the task object directly. The .output attribute provides better IDE support and makes task dependencies more explicit. Ruff takes this rule from Airflow. It is in preview.

Code
AIR201
Message
Use the `.output` attribute on the task object for "{}" instead of `xcom_pull` in a template string

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for @task-decorated functions whose multiple_outputs behavior is determined by Airflow's runtime inference rather than being set explicitly. AIR202

At runtime, Airflow infers multiple_outputs from the return type annotation: if it resolves to a subclass of collections.abc.Mapping, the return value is split into one XCom per key; otherwise it is stored as a single XCom. This couples typing to XCom layout in a non-obvious way — renaming, removing, or refining the return annotation silently changes the Dag's XCom behavior. Ruff takes this rule from Airflow. It is in preview.

Code
AIR202
Message
`@task`-decorated function relies on `multiple_outputs` inference

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of Airflow functions and values that have been moved to its providers (e.g., apache-airflow-providers-fab). AIR302

Airflow 3.0 moved various deprecated functions, members, and other values to its providers. The user needs to install the corresponding provider and replace the original usage with the one in the provider. Ruff takes this rule from Airflow and made it stable in 0.13.0.

Code
AIR302
Message
`{}` is moved into `{}` provider in Airflow 3.0;

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for Airflow function calls that will raise a runtime error in Airflow 3.0 due to function signature changes, such as functions that changed to accept only keyword arguments, parameter reordering, or parameter type changes. AIR303

Airflow 3.0 introduces changes to function signatures. Code that worked in Airflow 2.x will raise a runtime error if not updated in Airflow 3.0. Ruff takes this rule from Airflow and made it stable in 0.16.0.

Code
AIR303
Message
`{}` signature is changed in Airflow 3.0

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for calls to runtime-varying functions (such as datetime.now()) used as arguments in Airflow Dag or task constructors. AIR304

Using runtime-varying values as arguments to Dag or task constructors causes the serialized Dag hash to change on every parse, creating infinite Dag versions in the dag_version and serialized_dag tables. This leads to unbounded database growth and can eventually cause out-of-memory conditions. Ruff takes this rule from Airflow. It is in preview.

Code
AIR304
Message
`{}()` produces a value that changes at runtime; using it in a Dag or task argument causes infinite Dag version creation

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of deprecated Airflow functions and values that still have a compatibility layer. AIR311

Airflow 3.0 removed various deprecated functions, members, and other values. Some have more modern replacements. Others are considered too niche and not worth continued maintenance in Airflow. Even though these symbols still work fine on Airflow 3.0, they are expected to be removed in a future version. Where available, users should replace the removed functionality with the new alternatives. Ruff takes this rule from Airflow and made it stable in 0.13.0.

Code
AIR311
Message
`{}` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of Airflow functions and values that have been moved to its providers but still have a compatibility layer (e.g., apache-airflow-providers-standard). AIR312

Airflow 3.0 moved various deprecated functions, members, and other values to its providers. Even though these symbols still work fine on Airflow 3.0, they are expected to be removed in a future version. The user is suggested to install the corresponding provider and replace the original usage with the one in the provider. Ruff takes this rule from Airflow and made it stable in 0.13.0.

Code
AIR312
Message
`{}` is deprecated and moved into `{}` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that function arguments have type annotations. ANN001

Type annotations are a good way to document the types of function arguments. They also help catch bugs, when used alongside a type checker, by ensuring that the types of any provided arguments match expectation. Ruff takes this rule from flake8-annotations and made it stable in v0.0.105.

Code
ANN001
Message
Missing type annotation for function argument `{}`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that public functions and methods have return type annotations. ANN201

Type annotations are a good way to document the return types of functions. They also help catch bugs, when used alongside a type checker, by ensuring that the types of any returned values, and the types expected by callers, match expectation. Ruff takes this rule from flake8-annotations and made it stable in v0.0.105.

Code
ANN201
Message
Missing return type annotation for public function `{}`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that private functions and methods have return type annotations. ANN202

Type annotations are a good way to document the return types of functions. They also help catch bugs, when used alongside a type checker, by ensuring that the types of any returned values, and the types expected by callers, match expectation. Ruff takes this rule from flake8-annotations and made it stable in v0.0.105.

Code
ANN202
Message
Missing return type annotation for private function `{}`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that "special" methods, like __init__, __new__, and __call__, have return type annotations. ANN204

Type annotations are a good way to document the return types of functions. They also help catch bugs, when used alongside a type checker, by ensuring that the types of any returned values, and the types expected by callers, match expectation. Ruff takes this rule from flake8-annotations and made it stable in v0.0.105.

Code
ANN204
Message
Missing return type annotation for special method `{}`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that static methods have return type annotations. ANN205

Type annotations are a good way to document the return types of functions. They also help catch bugs, when used alongside a type checker, by ensuring that the types of any returned values, and the types expected by callers, match expectation. Ruff takes this rule from flake8-annotations and made it stable in v0.0.105.

Code
ANN205
Message
Missing return type annotation for staticmethod `{}`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that class methods have return type annotations. ANN206

Type annotations are a good way to document the return types of functions. They also help catch bugs, when used alongside a type checker, by ensuring that the types of any returned values, and the types expected by callers, match expectation. Ruff takes this rule from flake8-annotations and made it stable in v0.0.105.

Code
ANN206
Message
Missing return type annotation for classmethod `{}`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Notify about an annotation in an unchecked function. annotation-unchecked

Sometimes a user may accidentally omit an annotation for a function, and mypy will not check the body of this function (unless one uses --check-untyped-defs or --disallow-untyped-defs). To avoid such situations go unnoticed, mypy will show a note, if there are any type annotations in an unchecked function. mypy enables this error code by default.

Code
annotation-unchecked
Severity
note

Source: github.com, mypy.readthedocs.io. JSON record. This entry is a card. Help write this page.

Checks for timeout context managers which do not contain a checkpoint. ASYNC100

Some asynchronous context managers, such as asyncio.timeout and trio.move_on_after, have no effect unless they contain a checkpoint. The use of such context managers without an await, async with or async for statement is likely a mistake. Ruff takes this rule from flake8-async and made it stable in v0.0.269.

Code
ASYNC100
Message
A `with {}(...):` context does not contain any `await` statements. This makes it pointless, as the timeout can only be triggered by a checkpoint.

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for the use of an async sleep function in a while loop. ASYNC110

Busy-waiting for a condition in a loop forces a tradeoff between efficiency and latency: shorter sleep times improve responsiveness but waste more CPU cycles, while longer sleep times reduce CPU usage but delay reaction to state changes. Ruff takes this rule from flake8-async and made it stable in 0.5.0.

Code
ASYNC110
Message
Use `{}.Event` instead of awaiting `{}.sleep` in a `while` loop

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of trio.sleep() or anyio.sleep() with a delay greater than 24 hours. ASYNC116

Calling sleep() with a delay greater than 24 hours is usually intended to sleep indefinitely. Instead of using a large delay, trio.sleep_forever() or anyio.sleep_forever() better conveys the intent. Ruff takes this rule from flake8-async and made it stable in 0.13.0.

Code
ASYNC116
Message
`{}.sleep()` with >24 hour interval should usually be `{}.sleep_forever()`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for yield inside a context manager in an async generator. ASYNC119

Yielding inside a context manager in an async generator is unsafe because the cleanup of the context manager may be delayed until the generator is closed, at which point await is no longer allowed. This can lead to resource leaks or other bugs. Ruff takes this rule from flake8-async. It is in preview.

Code
ASYNC119
Message
Yield in context manager in async generator may not trigger cleanup

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that async functions do not contain blocking HTTP calls. ASYNC210

Blocking an async function via a blocking HTTP call will block the entire event loop, preventing it from executing other tasks while waiting for the HTTP response, negating the benefits of asynchronous programming. Ruff takes this rule from flake8-async and made it stable in 0.5.0.

Code
ASYNC210
Message
Async functions should not call blocking HTTP methods

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that async functions do not use blocking httpx clients. ASYNC212

Blocking an async function via a blocking HTTP call will block the entire event loop, preventing it from executing other tasks while waiting for the HTTP response, negating the benefits of asynchronous programming. Ruff takes this rule from flake8-async and made it stable in 0.15.0.

Code
ASYNC212
Message
Blocking httpx method {}.{}() in async context, use httpx.AsyncClient

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that async functions do not create subprocesses with blocking methods. ASYNC220

Blocking an async function via a blocking call will block the entire event loop, preventing it from executing other tasks while waiting for the call to complete, negating the benefits of asynchronous programming. Ruff takes this rule from flake8-async and made it stable in 0.5.0.

Code
ASYNC220
Message
Async functions should not create subprocesses with blocking methods

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that async functions do not run processes with blocking methods. ASYNC221

Blocking an async function via a blocking call will block the entire event loop, preventing it from executing other tasks while waiting for the call to complete, negating the benefits of asynchronous programming. Ruff takes this rule from flake8-async and made it stable in 0.5.0.

Code
ASYNC221
Message
Async functions should not run processes with blocking methods

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that async functions do not wait on processes with blocking methods. ASYNC222

Blocking an async function via a blocking call will block the entire event loop, preventing it from executing other tasks while waiting for the call to complete, negating the benefits of asynchronous programming. Ruff takes this rule from flake8-async and made it stable in 0.5.0.

Code
ASYNC222
Message
Async functions should not wait on processes with blocking methods

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that async functions do not open files with blocking methods like open. ASYNC230

Blocking an async function via a blocking call will block the entire event loop, preventing it from executing other tasks while waiting for the call to complete, negating the benefits of asynchronous programming. Ruff takes this rule from flake8-async and made it stable in 0.5.0.

Code
ASYNC230
Message
Async functions should not open files with blocking methods like `open`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that async functions do not call blocking os.path or pathlib.Path methods. ASYNC240

Calling some os.path or pathlib.Path methods in an async function will block the entire event loop, preventing it from executing other tasks while waiting for the operation. This negates the benefits of asynchronous programming. Ruff takes this rule from flake8-async and made it stable in 0.15.0.

Code
ASYNC240
Message
Async functions should not use {} methods, use trio.Path or anyio.path

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that async functions do not contain blocking usage of input from user. ASYNC250

Blocking an async function via a blocking input call will block the entire event loop, preventing it from executing other tasks while waiting for user input, negating the benefits of asynchronous programming. Ruff takes this rule from flake8-async and made it stable in 0.15.0.

Code
ASYNC250
Message
Blocking call to `input()` in async context

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks that async functions do not call time.sleep. ASYNC251

Blocking an async function via a time.sleep call will block the entire event loop, preventing it from executing other tasks while waiting for the time.sleep, negating the benefits of asynchronous programming. Ruff takes this rule from flake8-async and made it stable in 0.5.0.

Code
ASYNC251
Message
Async functions should not call `time.sleep`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for the attempted use of the unary prefix increment (++) or decrement operator (--). B002

Python does not support the unary prefix increment or decrement operator. Writing ++n is equivalent to +(+(n)) and writing --n is equivalent to -(-(n)). In both cases, it is equivalent to n. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.83.

Code
B002
Message
Python does not support the unary prefix increment operator (`++`)
Message
Python does not support the unary prefix decrement operator (`--`)

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of hasattr to test if an object is callable (e.g., hasattr(obj, "__call__")). B004

Using hasattr is an unreliable mechanism for testing if an object is callable. If obj implements a custom __getattr__, or if its __call__ is itself not callable, you may get misleading results. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.106.

Code
B004
Message
Using `hasattr(x, "__call__")` to test if x is callable is unreliable. Use `callable(x)` for consistent results.

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of multi-character strings in .strip(), .lstrip(), and .rstrip() calls. B005

All characters in the call to .strip(), .lstrip(), or .rstrip() are removed from the leading and trailing ends of the string. If the string contains multiple characters, the reader may be misled into thinking that a prefix or suffix is being removed, rather than a set of characters. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.106.

Code
B005
Message
Using `.strip()` with multi-character strings is misleading

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for function calls in default function arguments. B008

Any function call that's used in a default argument will only be performed once, at definition time. The returned value will then be reused by all calls to the function, which can lead to unexpected behaviour. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.102.

Code
B008
Message
Do not perform function call `{}` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
Message
Do not perform function call in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of getattr that take a constant attribute value as an argument (e.g., getattr(obj, "foo")). B009

getattr is used to access attributes dynamically. If the attribute is defined as a constant, it is no safer than a typical property access. When possible, prefer property access over getattr calls, as the former is more concise and idiomatic. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.110.

Code
B009
Message
Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of setattr that take a constant attribute value as an argument (e.g., setattr(obj, "foo", 42)). B010

setattr is used to set attributes dynamically. If the attribute is defined as a constant, it is no safer than a typical property access. When possible, prefer property access over setattr calls, as the former is more concise and idiomatic. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.111.

Code
B010
Message
Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of assert False. B011

Python removes assert statements when running in optimized mode (python -O), making assert False an unreliable means of raising an AssertionError. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.67.

Code
B011
Message
Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for exception handlers that catch duplicate exceptions. B014

Including the same exception multiple times in the same handler is redundant, as the first exception will catch the exception, making the second exception unreachable. The same applies to exception hierarchies, as a handler for a parent exception (like Exception) will also catch child exceptions (like ValueError). Ruff takes this rule from flake8-bugbear and made it stable in v0.0.67.

Code
B014
Message
Exception handler with duplicate exception: `{}`
Message
Exception handler with duplicate exceptions: {}

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for useless comparisons. B015

Useless comparisons have no effect on the program, and are often included by mistake. If the comparison is intended to enforce an invariant, prepend the comparison with an assert. Otherwise, remove it entirely. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.102.

Code
B015
Message
Pointless comparison. Did you mean to assign a value? Otherwise, prepend `assert` or remove it.
Message
Pointless comparison at end of function scope. Did you mean to return the expression result?

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for raise statements that raise a literal value. B016

raise must be followed by an exception instance or an exception class, and exceptions must be instances of BaseException or a subclass thereof. Raising a literal will raise a TypeError at runtime. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.102.

Code
B016
Message
Cannot raise a literal. Did you intend to return it or raise an Exception?

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for useless expressions. B018

Useless expressions have no effect on the program, and are often included by mistake. Assign a useless expression to a variable, or remove it entirely. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.100.

Code
B018
Message
Found useless expression. Either assign it to a variable or remove it.
Message
Found useless attribute access. Either assign it to a variable or remove it.

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of the functools.lru_cache and functools.cache decorators on methods. B019

Using the functools.lru_cache and functools.cache decorators on methods can lead to memory leaks, as the global cache will retain a reference to the instance, preventing it from being garbage collected. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.114.

Code
B019
Message
Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for docstrings that are written via f-strings. B021

Python will interpret the f-string as a joined string, rather than as a docstring. As such, the "docstring" will not be accessible via the __doc__ attribute, nor will it be picked up by any automated documentation tooling. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.116.

Code
B021
Message
f-string used as docstring. Python will interpret this as a joined string, rather than a docstring.

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for contextlib.suppress without arguments. B022

contextlib.suppress is a context manager that suppresses exceptions. It takes, as arguments, the exceptions to suppress within the enclosed block. If no exceptions are specified, then the context manager won't suppress any exceptions, and is thus redundant. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.118.

Code
B022
Message
No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for abstract classes without abstract methods or properties. B024

Annotated but unassigned class variables are regarded as abstract. Abstract base classes are used to define interfaces. If an abstract base class has no abstract methods or properties, you may have forgotten to add an abstract method or property to the class, or omitted an @abstractmethod decorator. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.118.

Code
B024
Message
`{}` is an abstract base class, but it has no abstract methods or properties

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for empty methods in abstract base classes without an abstract decorator. B027

Empty methods in abstract base classes without an abstract decorator may be be indicative of a mistake. If the method is meant to be abstract, add an @abstractmethod decorator to the method. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.118.

Code
B027
Message
`{}` is an empty method in an abstract base class, but has no abstract decorator

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for warnings.warn calls without an explicit stacklevel keyword argument. B028

The warnings.warn method uses a stacklevel of 1 by default, which will output a stack frame of the line on which the "warn" method is called. Setting it to a higher number will output a stack frame from higher up the stack. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.257.

Code
B028
Message
No explicit `stacklevel` keyword argument found

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for exception handlers that catch an empty tuple. B029

An exception handler that catches an empty tuple will not catch anything, and is indicative of a mistake. Instead, add exceptions to the except clause. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.250.

Code
B029
Message
Using `except* ():` with an empty tuple does not catch anything; add exceptions to handle
Message
Using `except ():` with an empty tuple does not catch anything; add exceptions to handle

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for set literals that contain duplicate items. B033

In Python, sets are unordered collections of unique elements. Including a duplicate item in a set literal is redundant, as the duplicate item will be replaced with a single item at runtime. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.271.

Code
B033
Message
Sets should not contain duplicate item `{}`
Message
Sets should not contain duplicate items, but `{}` and `{}` has the same value

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for calls to re.sub, re.subn, and re.split that pass count, maxsplit, or flags as positional arguments. B034

Passing count, maxsplit, or flags as positional arguments to re.sub, re.subn, or re.split can lead to confusion, as most methods in the re module accept flags as the third positional argument, while re.sub, re.subn, and re.split have different signatures. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.278.

Code
B034
Message
`{}` should pass `{}` and `flags` as keyword arguments to avoid confusion due to unintuitive argument positions

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for dictionary comprehensions that use a static key, like a string literal or a variable defined outside the comprehension. B035

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 flake8-bugbear and made it stable in v0.2.0.

Code
B035
Message
Dictionary comprehension uses static key: `{}`
Message
Dictionary comprehension uses static key

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for uses of delattr that take a constant attribute value as an argument (e.g., delattr(obj, "foo")). B043

delattr is used to delete attributes dynamically. If the attribute is defined as a constant, it is no safer than a typical property deletion. When possible, prefer del statements over delattr calls, as the former is more concise and idiomatic. Ruff takes this rule from flake8-bugbear. It is in preview.

Code
B043
Message
Do not call `delattr` with a constant attribute value. It is not any safer than normal property deletion.

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for return {value} statements in functions that also contain yield or yield from statements. B901

Using return {value} in a generator function was syntactically invalid in Python 2. In Python 3 return {value} _can_ be used in a generator; however, the combination of yield and return can lead to confusing behavior, as the return statement will cause the generator to raise StopIteration with the value provided, rather than returning the value to the caller. Ruff takes this rule from flake8-bugbear. It is in preview.

Code
B901
Message
Using `yield` and `return {}` in a generator function can lead to confusing behavior

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for raise statements in exception handlers that lack a from clause. B904

In Python, raise can be used with or without an exception from which the current exception is derived. This is known as exception chaining. When printing the stack trace, chained exceptions are displayed in such a way so as make it easier to trace the exception back to its root cause. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.138.

Code
B904
Message
Within an `except*` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
Message
Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for zip calls without an explicit strict parameter when called with two or more iterables, or any starred argument. B905

By default, if the iterables passed to zip are of different lengths, the resulting iterator will be silently truncated to the length of the shortest iterable. This can lead to subtle bugs. Ruff takes this rule from flake8-bugbear and made it stable in v0.0.167.

Code
B905
Message
`zip()` without an explicit `strict=` parameter

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for map calls without an explicit strict parameter when called with two or more iterables, or any starred argument. B912

By default, if the iterables passed to map are of different lengths, the resulting iterator will be silently truncated to the length of the shortest iterable. This can lead to subtle bugs. Ruff takes this rule from flake8-bugbear and made it stable in 0.15.0.

Code
B912
Message
`map()` without an explicit `strict=` parameter

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for except clauses that catch all exceptions. BLE001

This includes except BaseException and except Exception. Overly broad except clauses can lead to unexpected behavior, such as catching KeyboardInterrupt or SystemExit exceptions that prevent the user from exiting the program. Ruff takes this rule from flake8-blind-except and made it stable in v0.0.127.

Code
BLE001
Message
Do not catch blind exception: `{}`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Type variable name does not reflect variance…. C0105

Emitted when a TypeVar name doesn't reflect its type variance. According to PEP8, it is recommended to add suffixes '_co' and '_contra' to the variables used to declare covariant or contravariant behaviour respectively. Invariant (default) variables do not require a suffix. The message is also emitted when invariant variables do have a suffix. pylint calls it typevar-name-incorrect-variance.

Code
C0105
Severity
convention
Message
Type variable name does not reflect variance{}

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

Consider iterating the dictionary directly instead of calling .keys(). C0201

Emitted when the keys of a dictionary are iterated through the .keys() method or when .keys() is used for a membership check. It is enough to iterate through the dictionary itself, for key in dictionary. For membership checks, if key in dictionary is faster. pylint calls it consider-iterating-dictionary.

Code
C0201
Severity
convention
Message
Consider iterating the dictionary directly instead of calling .keys()

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

Class method … should have … as first argument. C0202

Used when a class method has a first argument named differently than the value specified in valid-classmethod-first-arg option (default to "cls"), recommended to easily differentiate them from regular instance methods. pylint calls it bad-classmethod-argument.

Code
C0202
Severity
convention
Message
Class method {} should have {} as first argument

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

Metaclass method … should have … as first argument. C0203

Used when a metaclass method has a first argument named differently than the value specified in valid-classmethod-first-arg option (default to "cls"), recommended to easily differentiate them from regular instance methods. pylint calls it bad-mcs-method-argument.

Code
C0203
Severity
convention
Message
Metaclass method {} should have {} as first argument

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

Metaclass class method … should have … as first argument. C0204

Used when a metaclass class method has a first argument named differently than the value specified in valid-metaclass-classmethod-first-arg option (default to "mcs"), recommended to easily differentiate them from regular instance methods. pylint calls it bad-mcs-classmethod-argument.

Code
C0204
Severity
convention
Message
Metaclass class method {} should have {} as first argument

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

Use … instead. C0207

Emitted when accessing only the first or last element of str.split(). The first and last element can be accessed by using str.split(sep, maxsplit=1)[0] or str.rsplit(sep, maxsplit=1)[-1] instead. pylint calls it use-maxsplit-arg.

Code
C0207
Severity
convention
Message
Use {} instead

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

Checks for unnecessary generators that can be rewritten as list comprehensions (or with list() directly). C400

It is unnecessary to use list() around a generator expression, since there are equivalent comprehensions for these types. Using a comprehension is clearer and more idiomatic. Ruff takes this rule from flake8-comprehensions and made it stable in v0.0.61.

Code
C400
Message
Unnecessary generator (rewrite using `list()`)
Message
Unnecessary generator (rewrite as a list comprehension)

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for unnecessary generators that can be rewritten as set comprehensions (or with set() directly). C401

It is unnecessary to use set around a generator expression, since there are equivalent comprehensions for these types. Using a comprehension is clearer and more idiomatic. Ruff takes this rule from flake8-comprehensions and made it stable in v0.0.61.

Code
C401
Message
Unnecessary generator (rewrite using `set()`)
Message
Unnecessary generator (rewrite as a set comprehension)

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for unnecessary dict(), list() or tuple() calls that can be rewritten as empty literals. C408

It's unnecessary to call, e.g., dict() as opposed to using an empty literal ({}). The former is slower because the name dict must be looked up in the global scope in case it has been rebound. Ruff takes this rule from flake8-comprehensions and made it stable in v0.0.61.

Code
C408
Message
Unnecessary `{}()` call (rewrite as a literal)

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for tuple calls that take unnecessary list or tuple literals as arguments. C409

It's unnecessary to use a list or tuple literal within a tuple() call, since there is a literal syntax for these types. Ruff takes this rule from flake8-comprehensions and made it stable in v0.0.66.

Code
C409
Message
Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
Message
Unnecessary tuple literal passed to `tuple()` (remove the outer call to `tuple()`)

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for list() calls that take unnecessary list or tuple literals as arguments. C410

It's unnecessary to use a list or tuple literal within a list() call, since there is a literal syntax for these types. Ruff takes this rule from flake8-comprehensions and made it stable in v0.0.66.

Code
C410
Message
Unnecessary list literal passed to `list()` (remove the outer call to `list()`)
Message
Unnecessary tuple literal passed to `list()` (rewrite as a single list literal)

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for unnecessary list(), reversed(), set(), sorted(), and tuple() call within list(), set(), sorted(), and tuple() calls. C414

It's unnecessary to double-cast or double-process iterables by wrapping the listed functions within an additional list(), set(), sorted(), or tuple() call. Doing so is redundant and can be confusing for readers. Ruff takes this rule from flake8-comprehensions and made it stable in v0.0.70.

Code
C414
Message
Unnecessary `{}()` call within `{}()`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for dict() calls that take unnecessary dict literals or dict comprehensions as arguments. C418

It's unnecessary to wrap a dict literal or comprehension within a dict() call, since the literal or comprehension syntax already returns a dictionary. Ruff takes this rule from flake8-comprehensions and made it stable in v0.0.262.

Code
C418
Message
Unnecessary dict {} passed to `dict()` (remove the outer call to `dict()`)

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for unnecessary list or set comprehensions passed to builtin functions that take an iterable. C419

Many builtin functions (this rule currently covers any and all in stable, along with min, max, and sum in preview) accept any iterable, including a generator. Constructing a temporary list via list comprehension is unnecessary and wastes memory for large iterables. Ruff takes this rule from flake8-comprehensions and made it stable in v0.0.262.

Code
C419
Message
Unnecessary list comprehension
Message
Unnecessary set comprehension

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for functions with a high McCabe complexity. C901

The McCabe complexity of a function is a measure of the complexity of the control flow graph of the function. It is calculated by adding one to the number of decision points in the function. A decision point is a place in the code where the program has a choice of two or more paths to follow. Ruff takes this rule from mccabe and made it stable in v0.0.127.

Code
C901
Message
`{}` is too complex ({} > {})

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty. C1802

Empty sequences are considered false in a boolean context. You can either remove the call to 'len' (if not x) or compare the length against a scalar (if len(x) > 1). pylint calls it use-implicit-booleaness-not-len.

Code
C1802
Severity
convention
Message
Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

"…" can be simplified to "…", if it is strictly a sequence, as an empty … is falsey. C1803

Empty sequences are considered false in a boolean context. Following this check blindly in weakly typed code base can create hard to debug issues. If the value can be something else that is falsey but not a sequence (for example None, an empty string, or 0) the code will not be equivalent. pylint calls it use-implicit-booleaness-not-comparison.

Code
C1803
Severity
convention
Message
"{}" can be simplified to "{}", if it is strictly a sequence, as an empty {} is falsey

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

"…" can be simplified to "…", if it is strictly a string, as an empty string is falsey. C1804

Empty string are considered false in a boolean context. Following this check blindly in weakly typed code base can create hard to debug issues. If the value can be something else that is falsey but not a string (for example None, an empty sequence, or 0) the code will not be equivalent. pylint calls it use-implicit-booleaness-not-comparison-to-string.

Code
C1804
Severity
convention
Message
"{}" can be simplified to "{}", if it is strictly a string, as an empty string is falsey

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

"…" can be simplified to "…", if it is strictly an int, as 0 is falsey. C1805

0 is considered false in a boolean context. Following this check blindly in weakly typed code base can create hard to debug issues. If the value can be something else that is falsey but not an int (for example None, an empty string, or an empty sequence) the code will not be equivalent. pylint calls it use-implicit-booleaness-not-comparison-to-zero.

Code
C1805
Severity
convention
Message
"{}" can be simplified to "{}", if it is strictly an int, as 0 is falsey

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

… name "…" contains a non-ASCII character, consider renaming it. C2401

Used when the name contains at least one non-ASCII unicode character. See https://peps.python.org/pep-0672/#confusing-features for a background why this could be bad. If your programming guideline defines that you are programming in English, then there should be no need for non ASCII characters in Python Names. If not you can simply disable this check. pylint calls it non-ascii-name.

Code
C2401
Severity
convention
Message
{} name "{}" contains a non-ASCII character, consider renaming it.

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

… name "…" contains a non-ASCII character, use an ASCII-only alias for import. C2403

Used when the name contains at least one non-ASCII unicode character. See https://peps.python.org/pep-0672/#confusing-features for a background why this could be bad. If your programming guideline defines that you are programming in English, then there should be no need for non ASCII characters in Python Names. If not you can simply disable this check. pylint calls it non-ascii-module-import.

Code
C2403
Severity
convention
Message
{} name "{}" contains a non-ASCII character, use an ASCII-only alias for import.

Source: github.com, pylint.readthedocs.io. JSON record. This entry is a card. Help write this page.

Checks for undocumented magic method definitions. D105

Magic methods (methods with names that start and end with double underscores) are used to implement operator overloading and other special behavior. Such methods should be documented via docstrings to outline their behavior. Ruff takes this rule from pydocstyle and made it stable in v0.0.70.

Code
D105
Message
Missing docstring in magic method

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for public __init__ method definitions that are missing docstrings. D107

Public __init__ methods are used to initialize objects. __init__ methods should be documented via docstrings to describe the method's behavior, arguments, side effects, exceptions, and any other information that may be relevant to the user. Ruff takes this rule from pydocstyle and made it stable in v0.0.70.

Code
D107
Message
Missing docstring in `__init__`

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for docstring summary lines that are not separated from the docstring description by one blank line. D205

PEP 257 recommends that multi-line docstrings consist of "a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description." Ruff takes this rule from pydocstyle and made it stable in v0.0.68.

Code
D205
Message
1 blank line required between summary line and description
Message
1 blank line required between summary line and description (found {})

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for multi-line docstrings whose closing quotes are not on their own line. D209

PEP 257 recommends that the closing quotes of a multi-line docstring be on their own line, for consistency and compatibility with documentation tools that may need to parse the docstring. Ruff takes this rule from pydocstyle and made it stable in v0.0.68.

Code
D209
Message
Multi-line docstring closing quotes should be on a separate line

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.

Checks for docstring summary lines that are not positioned on the first physical line of the docstring. D212

PEP 257 recommends that multi-line docstrings consist of "a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description." Ruff takes this rule from pydocstyle and made it stable in v0.0.69.

Code
D212
Message
Multi-line docstring summary should start at the first line

Source: docs.astral.sh. JSON record. This entry is a card. Help write this page.