If an assert x, y assertion fails, the Python interpreter raises an AssertionError, and the evaluated value of y is used as the contents of that assertion error. The print function always returns None, however, so the evaluated value of a call to print will always be None. Ruff takes this rule from Ruff-specific rules and made it stable in 0.8.0.
- Code
RUF030- Message
`print()` call in `assert` statement is likely unintentional
It is good to be consistent and, depending on the codebase, one or the other convention may be preferred. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF031- Message
Use parentheses for tuples in subscripts- Message
Avoid parentheses for tuples in subscripts
Float literals have limited precision that can lead to unexpected results. The Decimal class is designed to handle numbers with fixed-point precision, so a string literal should be used instead. Ruff takes this rule from Ruff-specific rules and made it stable in 0.9.0.
- Code
RUF032- Message
`Decimal()` called with float literal argument
Adding a default value to a parameter in a __post_init__ method has no impact on whether the parameter will have a default value in the dataclass's generated __init__ method. To create an init-only dataclass parameter with a default value, you should use an InitVar field in the dataclass's class body and give that InitVar field a default value. Ruff takes this rule from Ruff-specific rules and made it stable in 0.9.0.
- Code
RUF033- Message
`__post_init__` method with argument defaults
Useless if-else conditions add unnecessary complexity to the code without providing any logical benefit. Assigning the value directly is clearer. Ruff takes this rule from Ruff-specific rules and made it stable in 0.9.0.
- Code
RUF034- Message
Useless `if`-`else` condition
markupsafe.Markup does not perform any escaping, so passing dynamic content, like f-strings, variables or interpolated strings will potentially lead to XSS vulnerabilities. Ruff takes this rule from Ruff-specific rules, and removed it.
- Code
RUF035- Message
Unsafe use of `{}` detected
Type annotation unions are commutative, meaning that the order of the elements does not matter. The None literal represents the absence of a value. For readability, it's preferred to write the more informative type expressions first. Ruff takes this rule from Ruff-specific rules and made it stable in 0.16.0.
- Code
RUF036- Message
`None` not at the end of the type union.
It's unnecessary to use an empty literal as a deque's iterable, since this is already the default behavior. Ruff takes this rule from Ruff-specific rules and made it stable in 0.15.0.
- Code
RUF037- Message
Unnecessary empty iterable within a deque call
LiteralTrue, False can be replaced with bool in type annotations, which has the same semantic meaning but is more concise and readable. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF038- Message
`Literal[True, False, ...]` can be replaced with `Literal[...] | bool`- Message
`Literal[True, False]` can be replaced with `bool`
Regular expressions should be written using raw strings to avoid double escaping. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF039- Message
First argument to {} is not raw string- Message
First argument to {} is not raw bytes literal
An assert message which is a non-string literal was likely intended to be used in a comparison assertion, rather than as a message. Ruff takes this rule from Ruff-specific rules and made it stable in 0.10.0.
- Code
RUF040- Message
Non-string literal used as assert message
Prefer using a single Literal, which is equivalent and more concise. Ruff takes this rule from Ruff-specific rules and made it stable in 0.10.0.
- Code
RUF041- Message
Unnecessary nested `Literal`
The match argument is implicitly converted to a regex under the hood. It should be made explicit whether the string is meant to be a regex or a "plain" pattern by prefixing the string with the r suffix, escaping the metacharacter(s) in the string using backslashes, or wrapping the entire string in a call to re.escape(). Ruff takes this rule from Ruff-specific rules and made it stable in 0.13.0.
- Code
RUF043- Message
Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
Class variables are shared between all instances of that class. In dataclasses, fields with no annotations at all are implicitly considered class variables, and a TypeError is raised if a user attempts to initialize an instance of the class with this field. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF045- Message
Assignment without annotation found in dataclass body
Such a conversion is unnecessary. Ruff takes this rule from Ruff-specific rules and made it stable in 0.10.0.
- Code
RUF046- Message
Value being cast to `int` is already an integer
statements. Such an else clause does nothing and can be removed. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF047- Message
Empty `else` clause
__version__ does not always contain integral-like elements. Ruff takes this rule from Ruff-specific rules and made it stable in 0.10.0.
- Code
RUF048- Message
`__version__` may contain non-integral-like elements
Decorating an enum with @dataclass() does not cause any errors at runtime, but may cause erroneous results: Ruff takes this rule from Ruff-specific rules and made it stable in 0.12.0.
- Code
RUF049- Message
An enum class should not be decorated with `@dataclass`
An if statement with an empty body either does nothing (when the condition is side-effect-free) or could be replaced with just the condition expression (when it has side effects). This pattern commonly arises when auto-fixers remove unused imports from conditional blocks (e.g., version-dependent imports), leaving behind an empty skeleton. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF050- Message
Empty `if` statement
To remove a key-value pair from a dictionary, it's more concise to use .pop(..., None). Ruff takes this rule from Ruff-specific rules and made it stable in 0.10.0.
- Code
RUF051- Message
Use `pop` instead of `key in dict` followed by `del dict[key]`
Marking a variable with a leading underscore conveys that it is intentionally unused within the function or method. When these variables are later referenced in the code, it causes confusion and potential misunderstandings about the code's intention. If a variable marked as "unused" is subsequently used, it suggests that either the variable could be given a clearer name, or that the code is accidentally making use of the wrong variable. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF052- Message
Local dummy variable `{}` is accessed
Such classes cause errors at runtime: Ruff takes this rule from Ruff-specific rules and made it stable in 0.12.0.
- Code
RUF053- Message
Class with type parameter list inherits from `Generic`
The language reference states: Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF054- Message
Indented form feed
Performing checks on strings directly can make the code simpler, may require less escaping, and will often be faster. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF055- Message
Plain string pattern passed to `re` function
The default fallback None is already falsy. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF056- Message
Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
Rounding a value that's already an integer is unnecessary. It's clearer to use the value directly. Ruff takes this rule from Ruff-specific rules and made it stable in 0.12.0.
- Code
RUF057- Message
Value being rounded is already an integer
zip-ping iterables only to unpack them later from within starmap is unnecessary. For such cases, map() should be used instead. Ruff takes this rule from Ruff-specific rules and made it stable in 0.12.0.
- Code
RUF058- Message
`itertools.starmap` called on `zip` iterable
A variable that is defined but never used can confuse readers. Ruff takes this rule from Ruff-specific rules and made it stable in 0.13.0.
- Code
RUF059- Message
Unpacked variable `{}` is never used
If the collection is always empty, the check is unnecessary and can be removed. Ruff takes this rule from Ruff-specific rules and made it stable in 0.15.0.
- Code
RUF060- Message
Unnecessary membership test on empty collection
The context-manager form is more readable, easier to extend, and supports additional keyword arguments. Ruff takes this rule from Ruff-specific rules and made it stable in 0.15.0.
- Code
RUF061- Message
Use context-manager form of `pytest.{}()`
Starting with Python 3.14, directly accessing __annotations__ via foo.__dict__.get("__annotations__") or foo.__dict__"__annotations__" will only return annotations if the class is defined under from __future__ import annotations. Ruff takes this rule from Ruff-specific rules and made it stable in 0.16.0.
- Code
RUF063- Message
Use `{}` instead of `__dict__` access
Numeric modes are made up of one to four octal digits. Converting a non-octal integer to octal may not be the mode the author intended. Ruff takes this rule from Ruff-specific rules and made it stable in 0.15.0.
- Code
RUF064- Message
Non-octal mode
Arguments to logging calls will be formatted as strings automatically, so it is unnecessary and less efficient to eagerly format the arguments before passing them in. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF065- Message
Unnecessary `oct()` conversion when formatting with `%s`. Use `%#o` instead of `%s`- Message
Unnecessary `hex()` conversion when formatting with `%s`. Use `%#x` instead of `%s`- Message
Unnecessary `str()` conversion when formatting with `%s`- Message
Unnecessary `repr()` conversion when formatting with `%s`. Use `%r` instead of `%s`- Message
Unnecessary `ascii()` conversion when formatting with `%s`. Use `%a` instead of `%s`- Message
Unnecessary `bytes()` conversion when formatting with `%b`
Property methods are expected to return a computed value, a missing return in a property usually indicates an implementation mistake. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF066- Message
`{}` is a property without a `return` statement
__init__.py files are often empty or only contain simple code to modify a module's API. As such, it's easy to overlook them and their possible side effects when debugging. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF067- Message
`__init__` module should not contain any code- Message
`__init__` module should only contain docstrings and re-exports
Duplicate elements in __all__ serve no purpose and can indicate copy-paste errors or incomplete refactoring. Ruff takes this rule from Ruff-specific rules and made it stable in 0.16.0.
- Code
RUF068- Message
`__all__` contains duplicate entries
Directly comparing floating-point numbers for exact equality or inequality can lead to incorrect and non-deterministic outcomes. This is because floating-point values are finite binary approximations of real numbers. Many decimal values, such as 0.1, cannot be represented exactly in binary, leading to small rounding errors. Furthermore, the results of arithmetic operations are subject to rounding at each step, and the order of operations can influence the final result. Consequently, two mathematically equivalent computations may yield binary floating-point values that differ by a tiny margin. Relying on exact comparison treats these semantically equal values as different, breaking logical correctness. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF069- Message
Unreliable floating point equality comparison `{} {} {}`
The variable assignment is not necessary, as the value can be yielded directly. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF070- Message
Unnecessary assignment to `{}` before `yield from` statement- Message
Unnecessary assignment to `{}` before `yield` statement
os.path.commonprefix performs a character-by-character string comparison rather than comparing path components. This leads to incorrect results when paths share a common string prefix that is not a valid path component. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF071- Message
`os.path.commonprefix()` compares strings character-by-character
statements An empty finally clause is a no-op and adds unnecessary noise. If the try statement has except or else clauses, the finally clause can simply be removed. If it's a bare try/finally, the entire try statement can be replaced with its body Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF072- Message
Empty `finally` clause
F-strings already support interpolation via {...} expressions. Using the % operator on an f-string is almost certainly a mistake, since the f-string's interpolation and %-formatting serve the same purpose. This typically indicates that the developer intended to use either an f-string or %-formatting, but not both. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF073- Message
`%` operator used on an f-string
Decorators are applied bottom-up. Certain decorator combinations cause runtime errors or silent wrong behavior when placed in the wrong order. For example, @abstractmethod must be the innermost (bottom) decorator when combined with @property, @classmethod, or @staticmethod. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF074- Message
`@{}` should be placed after `@{}`
When a context manager is used, code after yield is intended to run during cleanup when the context exits. However, if an exception is raised inside the with block, code after an unprotected yield will never execute. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF075- Message
Context manager does not catch exceptions
A noqa directive that no longer matches any diagnostic violations is likely included by mistake, and should be removed to avoid confusion. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.155.
- Code
RUF100- Message
Unused {}- Message
Unused {} ({})- Message
Unused blanket {}
When one of Ruff's rule codes has been redirected, the implication is that the rule has been deprecated in favor of another rule or code. To keep your codebase consistent and up-to-date, prefer the canonical rule code over the deprecated code. Ruff takes this rule from Ruff-specific rules and made it stable in 0.6.0.
- Code
RUF101- Message
`{}` is a redirect to `{}`
Invalid rule codes serve no purpose and may indicate outdated code suppressions. Ruff takes this rule from Ruff-specific rules and made it stable in 0.15.0.
- Code
RUF102- Message
Invalid rule code in {}: {}
Invalid suppression comments are ignored by Ruff, and should either be fixed or removed to avoid confusion. Ruff takes this rule from Ruff-specific rules and made it stable in 0.15.0.
- Code
RUF103- Message
Invalid suppression comment: {}
Unmatched range suppression comments can inadvertently suppress violations over larger sections of code than intended, particularly at module scope. Ruff takes this rule from Ruff-specific rules and made it stable in 0.15.0.
- Code
RUF104- Message
Suppression comment without matching `#ruff:enable` comment
ruff: ignore comments allow the use of rule names instead of codes and can be used in more places than noqa comments. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF105- Message
`noqa` comment used instead of `ruff: ignore`- Message
`ruff: noqa` comment used instead of `ruff: file-ignore`
Human-readable rule names are easier to understand than rule codes. Using names also avoids requiring readers to look up the meaning of each code. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF106- Message
Rule code used instead of name in suppression comment
Your project may contain invalid metadata or configuration without you noticing. Ruff takes this rule from Ruff-specific rules and made it stable in v0.0.271.
- Code
RUF200- Message
Failed to parse pyproject.toml: {}
Human-readable rule names are easier to understand than rule codes. Using names also avoids requiring readers to look up the meaning of each code. Ruff takes this rule from Ruff-specific rules. It is in preview.
- Code
RUF201- Message
Rule code used instead of name in `lint.{}`- Message
Rule code used instead of name in `{}`
Assertions are removed when Python is run with optimization requested (i.e., when the -O flag is present), which is a common practice in production environments. As such, assertions should not be used for runtime validation of user input or to enforce interface constraints. Ruff takes this rule from flake8-bandit and made it stable in v0.0.116.
- Code
S101- Message
Use of `assert` detected
The exec() function is insecure as it allows for arbitrary code execution. Ruff takes this rule from flake8-bandit and made it stable in v0.0.116.
- Code
S102- Message
Use of `exec` detected
Overly permissive file permissions may allow unintended access and arbitrary code execution. Ruff takes this rule from flake8-bandit and made it stable in v0.0.211.
- Code
S103- Message
`os.chmod` setting a permissive mask `{mask:#o}` on file or directory- Message
`os.chmod` setting an invalid mask on file or directory
Binding to all network interfaces is insecure as it allows access from unintended interfaces, which may be poorly secured or unauthorized. Ruff takes this rule from flake8-bandit and made it stable in v0.0.116.
- Code
S104- Message
Possible binding to all interfaces
Including a hardcoded password in source code is a security risk, as an attacker could discover the password and use it to gain unauthorized access. Ruff takes this rule from flake8-bandit and made it stable in v0.0.116.
- Code
S105- Message
Possible hardcoded password assigned to: "{}"
Including a hardcoded password in source code is a security risk, as an attacker could discover the password and use it to gain unauthorized access. Ruff takes this rule from flake8-bandit and made it stable in v0.0.116.
- Code
S106- Message
Possible hardcoded password assigned to argument: "{}"
Including a hardcoded password in source code is a security risk, as an attacker could discover the password and use it to gain unauthorized access. Ruff takes this rule from flake8-bandit and made it stable in v0.0.116.
- Code
S107- Message
Possible hardcoded password assigned to function default: "{}"
The use of hardcoded paths for temporary files can be insecure. If an attacker discovers the location of a hardcoded path, they can replace the contents of the file or directory with a malicious payload. Ruff takes this rule from flake8-bandit and made it stable in v0.0.211.
- Code
S108- Message
Probable insecure usage of temporary file or directory: "{}"
The try-except-pass pattern suppresses all exceptions. Suppressing exceptions may hide errors that could otherwise reveal unexpected behavior, security vulnerabilities, or malicious activity. Instead, consider logging the exception. Ruff takes this rule from flake8-bandit and made it stable in v0.0.237.
- Code
S110- Message
`try`-`except`-`pass` detected, consider logging the exception
The try-except-continue pattern suppresses all exceptions. Suppressing exceptions may hide errors that could otherwise reveal unexpected behavior, security vulnerabilities, or malicious activity. Instead, consider logging the exception. Ruff takes this rule from flake8-bandit and made it stable in v0.0.245.
- Code
S112- Message
`try`-`except`-`continue` detected, consider logging the exception
The timeout parameter is used to set the maximum time to wait for a response from the server. By omitting the timeout parameter, the program may hang indefinitely while awaiting a response. Ruff takes this rule from flake8-bandit and made it stable in v0.0.213.
- Code
S113- Message
Probable use of `{}` call without timeout- Message
Probable use of `{}` call with timeout set to `None`
Enabling debug mode shows an interactive debugger in the browser if an error occurs, and allows running arbitrary Python code from the browser. This could leak sensitive information, or allow an attacker to run arbitrary code. Ruff takes this rule from flake8-bandit and made it stable in v0.2.0.
- Code
S201- Message
Use of `debug=True` in Flask app detected
Extracting archives from untrusted sources without prior inspection is a security risk, as maliciously crafted archives may contain files that will be written outside of the target directory. For example, the archive could include files with absolute paths (e.g., /etc/passwd), or relative paths with parent directory references (e.g., ../etc/passwd). Ruff takes this rule from flake8-bandit and made it stable in v0.2.0.
- Code
S202- Message
Uses of `tarfile.extractall()`
Deserializing untrusted data with pickle and other deserialization modules is insecure as it can allow for the creation of arbitrary objects, which can then be used to achieve arbitrary code execution and otherwise unexpected behavior. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S301- Message
`pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue
Deserializing untrusted data with marshal is insecure, as it can allow for the creation of arbitrary objects, which can then be used to achieve arbitrary code execution and otherwise unexpected behavior. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S302- Message
Deserialization with the `marshal` module is possibly dangerous
Weak or broken cryptographic hash functions may be susceptible to collision attacks (where two different inputs produce the same hash) or pre-image attacks (where an attacker can find an input that produces a given hash). This can lead to security vulnerabilities in applications that rely on these hash functions. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S303- Message
Use of insecure MD2, MD4, MD5, or SHA1 hash function
Weak or broken cryptographic ciphers may be susceptible to attacks that allow an attacker to decrypt ciphertext without knowing the key or otherwise compromise the security of the cipher, such as forgeries. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S304- Message
Use of insecure cipher, replace with a known secure cipher such as AES
Weak or broken cryptographic ciphers may be susceptible to attacks that allow an attacker to decrypt ciphertext without knowing the key or otherwise compromise the security of the cipher, such as forgeries. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S305- Message
Use of insecure block cipher mode, replace with a known secure mode such as CBC or CTR
tempfile.mktemp returns a pathname of a file that does not exist at the time the call is made; then, the caller is responsible for creating the file and subsequently using it. This is insecure because another process could create a file with the same name between the time the function returns and the time the caller creates the file. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S306- Message
Use of insecure and deprecated function (`mktemp`)
The eval() function is insecure as it enables arbitrary code execution. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S307- Message
Use of possibly insecure function; consider using `ast.literal_eval`
Cross-site scripting (XSS) vulnerabilities allow attackers to execute arbitrary JavaScript. To guard against XSS attacks, Django templates assumes that data is unsafe and automatically escapes malicious strings before rending them. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S308- Message
Use of `mark_safe` may expose cross-site scripting vulnerabilities
Some URL open functions allow the use of file: or custom schemes (for use instead of http: or https:). An attacker may be able to use these schemes to access or modify unauthorized resources, and cause unexpected behavior. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S310- Message
Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.
Cryptographically weak pseudo-random number generators are insecure, as they are easily predictable. This can allow an attacker to guess the generated numbers and compromise the security of the system. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S311- Message
Standard pseudo-random generators are not suitable for cryptographic purposes
Telnet is considered insecure because it does not encrypt data sent over the connection and is vulnerable to numerous attacks. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S312- Message
Telnet is considered insecure. Use SSH or some other encrypted protocol.
Many XML parsers are vulnerable to XML attacks (such as entity expansion), which cause excessive memory and CPU usage by exploiting recursion. An attacker could use such methods to access unauthorized resources. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S313- Message
Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents
Many XML parsers are vulnerable to XML attacks (such as entity expansion), which cause excessive memory and CPU usage by exploiting recursion. An attacker could use such methods to access unauthorized resources. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S314- Message
Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents
Many XML parsers are vulnerable to XML attacks (such as entity expansion), which cause excessive memory and CPU usage by exploiting recursion. An attacker could use such methods to access unauthorized resources. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S315- Message
Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents
Many XML parsers are vulnerable to XML attacks (such as entity expansion), which cause excessive memory and CPU usage by exploiting recursion. An attacker could use such methods to access unauthorized resources. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S316- Message
Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents
Many XML parsers are vulnerable to XML attacks (such as entity expansion), which cause excessive memory and CPU usage by exploiting recursion. An attacker could use such methods to access unauthorized resources. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S317- Message
Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents
Many XML parsers are vulnerable to XML attacks (such as entity expansion), which cause excessive memory and CPU usage by exploiting recursion. An attacker could use such methods to access unauthorized resources. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S318- Message
Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents
Many XML parsers are vulnerable to XML attacks (such as entity expansion), which cause excessive memory and CPU usage by exploiting recursion. An attacker could use such methods to access unauthorized resources. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S319- Message
Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents
Many XML parsers are vulnerable to XML attacks (such as entity expansion), which cause excessive memory and CPU usage by exploiting recursion. An attacker could use such methods to access unauthorized resources. Ruff takes this rule from flake8-bandit, and removed it.
- Code
S320- Message
Using `lxml` to parse untrusted data is known to be vulnerable to XML attacks
FTP is considered insecure as it does not encrypt data sent over the connection and is thus vulnerable to numerous attacks. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S321- Message
FTP-related functions are being called. FTP is considered insecure. Use SSH/SFTP/SCP or some other encrypted protocol.
PEP 476 enabled certificate and hostname validation by default in Python standard library HTTP clients. Previously, Python did not validate certificates by default, which could allow an attacker to perform a "man in the middle" attack by intercepting and modifying traffic between client and server. Ruff takes this rule from flake8-bandit and made it stable in v0.0.258.
- Code
S323- Message
Python allows using an insecure context via the `_create_unverified_context` that reverts to the previous behavior that does not validate certificates or perform hostname checks.
Weak or broken cryptographic hash functions may be susceptible to collision attacks (where two different inputs produce the same hash) or pre-image attacks (where an attacker can find an input that produces a given hash). This can lead to security vulnerabilities in applications that rely on these hash functions. Ruff takes this rule from flake8-bandit and made it stable in v0.0.212.
- Code
S324- Message
Probable use of insecure hash functions in `{}`: `{}`
Telnet is considered insecure. It is deprecated since version 3.11, and was removed in version 3.13. Instead, use SSH or another encrypted protocol. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S401- Message
`telnetlib` and related modules are considered insecure. Use SSH or another encrypted protocol.
FTP is considered insecure. Instead, use SSH, SFTP, SCP, or another encrypted protocol. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S402- Message
`ftplib` and related modules are considered insecure. Use SSH, SFTP, SCP, or another encrypted protocol.
It is possible to construct malicious pickle data which will execute arbitrary code during unpickling. Consider possible security implications associated with these modules. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S403- Message
`pickle`, `cPickle`, `dill`, and `shelve` modules are possibly insecure
It is possible to inject malicious commands into subprocess calls. Consider possible security implications associated with this module. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S404- Message
`subprocess` module is possibly insecure
Using various methods from these modules to parse untrusted XML data is known to be vulnerable to XML attacks. Replace vulnerable imports with the equivalent defusedxml package, or make sure defusedxml.defuse_stdlib() is called before parsing XML data. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S405- Message
`xml.etree` methods are vulnerable to XML attacks
Using various methods from these modules to parse untrusted XML data is known to be vulnerable to XML attacks. Replace vulnerable imports with the equivalent defusedxml package, or make sure defusedxml.defuse_stdlib() is called before parsing XML data. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S406- Message
`xml.sax` methods are vulnerable to XML attacks
Using various methods from these modules to parse untrusted XML data is known to be vulnerable to XML attacks. Replace vulnerable imports with the equivalent defusedxml package, or make sure defusedxml.defuse_stdlib() is called before parsing XML data. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S407- Message
`xml.dom.expatbuilder` is vulnerable to XML attacks
Using various methods from these modules to parse untrusted XML data is known to be vulnerable to XML attacks. Replace vulnerable imports with the equivalent defusedxml package, or make sure defusedxml.defuse_stdlib() is called before parsing XML data. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S408- Message
`xml.dom.minidom` is vulnerable to XML attacks
Using various methods from these modules to parse untrusted XML data is known to be vulnerable to XML attacks. Replace vulnerable imports with the equivalent defusedxml package, or make sure defusedxml.defuse_stdlib() is called before parsing XML data. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S409- Message
`xml.dom.pulldom` is vulnerable to XML attacks
Using various methods from the lxml module to parse untrusted XML data is known to be vulnerable to XML attacks. Replace vulnerable imports with the equivalent defusedxml package. Ruff takes this rule from flake8-bandit, and removed it.
- Code
S410- Message
`lxml` is vulnerable to XML attacks
XMLRPC is a particularly dangerous XML module, as it is also concerned with communicating data over a network. Use the defused.xmlrpc.monkey_patch() function to monkey-patch the xmlrpclib module and mitigate remote XML attacks. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S411- Message
XMLRPC is vulnerable to remote XML attacks
httpoxy is a set of vulnerabilities that affect application code running in CGI or CGI-like environments. The use of CGI for web applications should be avoided to prevent this class of attack. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S412- Message
`httpoxy` is a set of vulnerabilities that affect application code running inCGI, or CGI-like environments. The use of CGI for web applications should be avoided
The pycrypto library is known to have a publicly disclosed buffer overflow vulnerability. It is no longer actively maintained and has been deprecated in favor of the pyca/cryptography library. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S413- Message
`pycrypto` library is known to have publicly disclosed buffer overflow vulnerability
pyghmi is an IPMI-related module, but IPMI is considered insecure. Instead, use an encrypted protocol. Ruff takes this rule from flake8-bandit. It is in preview.
- Code
S415- Message
An IPMI-related module is being imported. Prefer an encrypted protocol over IPMI.
If SSL certificates are not verified, an attacker could perform a "man in the middle" attack by intercepting and modifying traffic between the client and server. Ruff takes this rule from flake8-bandit and made it stable in v0.0.213.
- Code
S501- Message
Probable use of `{}` call with `verify=False` disabling SSL certificate checks
Several highly publicized exploitable flaws have been discovered in all versions of SSL and early versions of TLS. The following versions are considered insecure, and should be avoided: - SSL v2 - SSL v3 - TLS v1 - TLS v1.1 Ruff takes this rule from flake8-bandit and made it stable in v0.2.0.
- Code
S502- Message
Call made with insecure SSL protocol: `{}`
Several highly publicized exploitable flaws have been discovered in all versions of SSL and early versions of TLS. The following versions are considered insecure, and should be avoided: - SSL v2 - SSL v3 - TLS v1 - TLS v1.1 Ruff takes this rule from flake8-bandit and made it stable in v0.2.0.
- Code
S503- Message
Argument default set to insecure SSL protocol: `{}`
This method is known to provide a default value that maximizes compatibility, but permits use of insecure protocols. Ruff takes this rule from flake8-bandit and made it stable in v0.2.0.
- Code
S504- Message
`ssl.wrap_socket` called without an `ssl_version``
Small keys are easily breakable. For DSA and RSA, keys should be at least 2048 bits long. For EC, keys should be at least 224 bits long. Ruff takes this rule from flake8-bandit and made it stable in v0.2.0.
- Code
S505- Message
{} key sizes below {} bits are considered breakable
Running the yaml.load function over untrusted YAML files is insecure, as yaml.load allows for the creation of arbitrary Python objects, which can then be used to execute arbitrary code. Ruff takes this rule from flake8-bandit and made it stable in v0.0.212.
- Code
S506- Message
Probable use of unsafe loader `{}` with `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`.- Message
Probable use of unsafe `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`.
By default, Paramiko checks the identity of the remote host when establishing an SSH connection. Disabling the verification might lead to the client connecting to a malicious host, without the client knowing. Ruff takes this rule from flake8-bandit and made it stable in v0.2.0.
- Code
S507- Message
Paramiko call with policy set to automatically trust the unknown host key
The SNMPv1 and SNMPv2 protocols are considered insecure as they do not support encryption. Instead, prefer SNMPv3, which supports encryption. Ruff takes this rule from flake8-bandit and made it stable in v0.0.218.
- Code
S508- Message
The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able.
Unencrypted SNMPv3 communication can be intercepted and read by unauthorized parties. Instead, enable encryption when using SNMPv3. Ruff takes this rule from flake8-bandit and made it stable in v0.0.218.
- Code
S509- Message
You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure.
paramiko calls allow users to execute arbitrary shell commands on a remote machine. If the inputs to these calls are not properly sanitized, they can be vulnerable to shell injection attacks. Ruff takes this rule from flake8-bandit and made it stable in v0.0.270.
- Code
S601- Message
Possible shell injection via Paramiko call; check inputs are properly sanitized
Starting a subprocess with a shell can allow attackers to execute arbitrary shell commands. Consider starting the process without a shell call and sanitize the input to mitigate the risk of shell injection. Ruff takes this rule from flake8-bandit and made it stable in v0.0.262.
- Code
S602- Message
`subprocess` call with `shell=True` seems safe, but may be changed in the future; consider rewriting without `shell`- Message
`subprocess` call with `shell=True` identified, security issue- Message
`subprocess` call with truthy `shell` seems safe, but may be changed in the future; consider rewriting without `shell`- Message
`subprocess` call with truthy `shell` identified, security issue
Starting a subprocess without a shell can prevent attackers from executing arbitrary shell commands; however, it is still error-prone. Consider validating the input. Ruff takes this rule from flake8-bandit and made it stable in v0.0.262.
- Code
S603- Message
`subprocess` call: check for execution of untrusted input
Setting the shell parameter to true or another truthy value when invoking a subprocess can introduce security vulnerabilities, as it allows shell metacharacters and whitespace to be passed to child processes, potentially leading to shell injection attacks. Ruff takes this rule from flake8-bandit and made it stable in v0.0.262.
- Code
S604- Message
Function call with `shell=True` parameter identified, security issue- Message
Function call with truthy `shell` parameter identified, security issue
Starting a process with a shell can introduce security risks, such as code injection vulnerabilities. It's important to be aware of whether the usage of the shell is safe or not. Ruff takes this rule from flake8-bandit and made it stable in v0.0.262.
- Code
S605- Message
Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without `shell`- Message
Starting a process with a shell, possible injection detected
Invoking any kind of external executable via a function call can pose security risks if arbitrary variables are passed to the executable, or if the input is otherwise unsanitised or unvalidated. Ruff takes this rule from flake8-bandit and made it stable in v0.0.262.
- Code
S606- Message
Starting a process without a shell
Starting a process with a partial executable path can allow attackers to execute an arbitrary executable by adjusting the PATH environment variable. Consider using a full path to the executable instead. Ruff takes this rule from flake8-bandit and made it stable in v0.0.262.
- Code
S607- Message
Starting a process with a partial executable path
SQL injection is a common attack vector for web applications. Directly interpolating user input into SQL statements should always be avoided. Instead, favor parameterized queries, in which the SQL statement is provided separately from its parameters, as supported by psycopg3 and other database drivers and ORMs. Ruff takes this rule from flake8-bandit and made it stable in v0.0.245.
- Code
S608- Message
Possible SQL injection vector through string-based query construction
Wildcard injections can lead to unexpected behavior if unintended files are matched by the wildcard. Consider using a more specific path instead. Ruff takes this rule from flake8-bandit and made it stable in v0.0.271.
- Code
S609- Message
Possible wildcard injection in call due to `*` usage
Django's extra function can be used to execute arbitrary SQL queries, which can in turn lead to SQL injection vulnerabilities. Ruff takes this rule from flake8-bandit and made it stable in 0.5.0.
- Code
S610- Message
Use of Django `extra` can lead to SQL injection vulnerabilities
Django's RawSQL function can be used to execute arbitrary SQL queries, which can in turn lead to SQL injection vulnerabilities. Ruff takes this rule from flake8-bandit and made it stable in v0.2.0.
- Code
S611- Message
Use of `RawSQL` can lead to SQL injection vulnerabilities
logging.config.listen starts a server that listens for logging configuration requests. This is insecure, as parts of the configuration are passed to the built-in eval function, which can be used to execute arbitrary code. Ruff takes this rule from flake8-bandit and made it stable in v0.0.231.
- Code
S612- Message
Use of insecure `logging.config.listen` detected
jinja2 templates that use autoescape=False are vulnerable to cross-site scripting (XSS) attacks that allow attackers to execute arbitrary JavaScript. Ruff takes this rule from flake8-bandit and made it stable in v0.0.220.
- Code
S701- Message
Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function.- Message
By default, jinja2 sets `autoescape` to `False`. Consider using `autoescape=True` or the `select_autoescape` function to mitigate XSS vulnerabilities.
Mako templates allow HTML and JavaScript rendering by default, and are inherently open to XSS attacks. Ensure variables in all templates are properly escaped via the h (HTML) or x (XML) filters, depending on context. For example, to HTML escape the variable data, use ${ data |h }. Ruff takes this rule from flake8-bandit and made it stable in v0.2.0.
- Code
S702- Message
Mako templates allow HTML and JavaScript rendering by default and are inherently open to XSS attacks
markupsafe.Markup does not perform any escaping, so passing dynamic content, like f-strings, variables or interpolated strings will potentially lead to XSS vulnerabilities. Ruff takes this rule from flake8-bandit and made it stable in 0.10.0.
- Code
S704- Message
Unsafe use of `{}` detected
Abstract methods often don't have any default implementation, i.e. their bodies are just empty. Calling such methods in subclasses via super() will cause runtime errors, so mypy prevents you from doing so. mypy enables this error code by default.
- Code
safe-super- Severity
- error
To check if an object is an instance of any one of multiple types or classes, it is unnecessary to use multiple isinstance calls, as the second argument of the isinstance built-in function accepts a tuple of types and classes. Ruff takes this rule from flake8-simplify and made it stable in v0.0.212.
- Code
SIM101- Message
Multiple `isinstance` calls for `{}`, merge into a single call- Message
Multiple `isinstance` calls for expression, merge into a single call
Nesting if statements leads to deeper indentation and makes code harder to read. Instead, combine the conditions into a single if statement with an and operator. Ruff takes this rule from flake8-simplify and made it stable in v0.0.211.
- Code
SIM102- Message
Use a single `if` statement instead of nested `if` statements
if statements that return True for a truthy condition and False for a falsy condition can be replaced with boolean casts. Ruff takes this rule from flake8-simplify and made it stable in v0.0.214.
- Code
SIM103- Message
Return the condition `{}` directly- Message
Return the negated condition directly- Message
Return the condition directly
Using contextlib.suppress is more concise and directly communicates the intent of the code: to suppress a given exception. Ruff takes this rule from flake8-simplify and made it stable in v0.0.211.
- Code
SIM105- Message
Use `contextlib.suppress({})` instead of `try`-`except`-`pass`
The return statement in a finally block will always be executed, even if an exception is raised in the try or except block. This can lead to unexpected behavior. Ruff takes this rule from flake8-simplify and made it stable in v0.0.211.
- Code
SIM107- Message
Don't use `return` in `try`-`except` and `finally`
if-else-blocks that assign a value to a variable in both branches can be expressed more concisely by using a ternary or binary operator. Ruff takes this rule from flake8-simplify and made it stable in v0.0.213.
- Code
SIM108- Message
Use ternary operator `{}` instead of `if`-`else`-block- Message
Use binary operator `{}` instead of `if`-`else`-block
To check if an object is equal to any one of multiple values, it's more concise to use the in operator with a tuple of values. Ruff takes this rule from flake8-simplify and made it stable in v0.0.213.
- Code
SIM109- Message
Use `{}` instead of multiple equality comparisons
Using a builtin function is more concise and readable. Ruff takes this rule from flake8-simplify and made it stable in v0.0.211.
- Code
SIM110- Message
Use `{}` instead of `for` loop
By convention, environment variables should be capitalized. Ruff takes this rule from flake8-simplify and made it stable in v0.0.218.
- Code
SIM112- Message
Use capitalized environment variable `{}` instead of `{}`- Message
Use capitalized environment variable
When iterating over a sequence, it's often desirable to keep track of the index of each element alongside the element itself. Prefer the enumerate builtin over manually incrementing a counter variable within the loop, as enumerate is more concise and idiomatic. Ruff takes this rule from flake8-simplify and made it stable in v0.2.0.
- Code
SIM113- Message
Use `enumerate()` for index variable `{}` in `for` loop
If multiple arms of an if statement have the same body, using or better signals the intent of the statement. Ruff takes this rule from flake8-simplify and made it stable in v0.0.246.
- Code
SIM114- Message
Combine `if` branches using logical `or` operator
If a file is opened without a context manager, it is not guaranteed that the file will be closed (e.g., if an exception is raised), which can cause resource leaks. The rule detects a wide array of IO calls where context managers could be used, such as open, pathlib.Path(...).open(), tempfile.TemporaryFile() ortarfile.TarFile(...).gzopen(). Ruff takes this rule from flake8-simplify and made it stable in v0.0.219.
- Code
SIM115- Message
Use a context manager for opening files
These can be simplified by using a dictionary Ruff takes this rule from flake8-simplify and made it stable in v0.0.250.
- Code
SIM116- Message
Use a dictionary instead of consecutive `if` statements
In Python 3, a single with block can include multiple context managers. Ruff takes this rule from flake8-simplify and made it stable in v0.0.211.
- Code
SIM117- Message
Use a single `with` statement with multiple contexts instead of nested `with` statements
When checking for the existence of a key in a given dictionary, using key in dict is more readable and efficient than key in dict.keys(), while having the same semantics. Ruff takes this rule from flake8-simplify and made it stable in v0.0.176.
- Code
SIM118- Message
Use `key {} dict` instead of `key {} dict.keys()`
Negated == operators are less readable than != operators. When testing for non-equality, it is more common to use != than ==. Ruff takes this rule from flake8-simplify and made it stable in v0.0.213.
- Code
SIM201- Message
Use `{} != {}` instead of `not {} == {}`
Negated != operators are less readable than == operators, as they avoid a double negation. Ruff takes this rule from flake8-simplify and made it stable in v0.0.213.
- Code
SIM202- Message
Use `{} == {}` instead of `not {} != {}`
A double negation is redundant and less readable than omitting the not operators entirely. Ruff takes this rule from flake8-simplify and made it stable in v0.0.213.
- Code
SIM208- Message
Use `{}` instead of `not (not {})`
if expressions that evaluate to True for a truthy condition an False for a falsey condition can be replaced with bool() calls, which are more concise and readable. Ruff takes this rule from flake8-simplify and made it stable in v0.0.214.
- Code
SIM210- Message
Remove unnecessary `True if ... else False`- Message
Use `bool(...)` instead of `True if ... else False`
if expressions that evaluate to False for a truthy condition and True for a falsey condition can be replaced with not operators, which are more concise and readable. Ruff takes this rule from flake8-simplify and made it stable in v0.0.214.
- Code
SIM211- Message
Use `not ...` instead of `False if ... else True`
if expressions that check against a negated condition are more difficult to read than if expressions that check against the condition directly. Ruff takes this rule from flake8-simplify and made it stable in v0.0.214.
- Code
SIM212- Message
Use `{} if {} else {}` instead of `{} if not {} else {}`
An and expression that includes both an expression and its negation will always evaluate to False. Ruff takes this rule from flake8-simplify and made it stable in v0.0.211.
- Code
SIM220- Message
Use `False` instead of `{} and not {}`
An or expression that includes both an expression and its negation will always evaluate to True. Ruff takes this rule from flake8-simplify and made it stable in v0.0.211.
- Code
SIM221- Message
Use `True` instead of `{} or not {}`
If the expression is used as a condition, it can be replaced in-full with True. Ruff takes this rule from flake8-simplify and made it stable in v0.0.208.
- Code
SIM222- Message
Use `{}` instead of `{}`
If the expression is used as a condition, it can be replaced in-full with False. Ruff takes this rule from flake8-simplify and made it stable in v0.0.208.
- Code
SIM223- Message
Use `{}` instead of `{}`
These conditions (sometimes referred to as "Yoda conditions") are less readable than conditions that place the variable on the left-hand side of the comparison operator. Ruff takes this rule from flake8-simplify and made it stable in v0.0.207.
- Code
SIM300- Message
Yoda condition detected
dict.get() calls can be used to replace if statements that assign a value to a variable in both branches, falling back to a default value if the key is not found. When possible, using dict.get is more concise and more idiomatic. Ruff takes this rule from flake8-simplify and made it stable in v0.0.219.
- Code
SIM401- Message
Use `{}` instead of an `if` block
List literals are more readable and do not require the overhead of calling str.split. Ruff takes this rule from flake8-simplify and made it stable in 0.10.0.
- Code
SIM905- Message
Consider using a list literal instead of `str.{}`
None is the default value for dict.get(), so it is redundant to pass it explicitly. Ruff takes this rule from flake8-simplify and made it stable in v0.0.261.
- Code
SIM910- Message
Use `{}` instead of `{}`- Message
Use `dict.get()` without default value
The dict type provides an .items() method which is faster and more readable. Ruff takes this rule from flake8-simplify and made it stable in v0.2.0.
- Code
SIM911- Message
Use `{}` instead of `{}`- Message
Use `dict.items()` instead of `zip(dict.keys(), dict.values())`
In Python, the convention is such that class members that are prefixed with a single underscore, or prefixed but not suffixed with a double underscore, are considered private and intended for internal use. Ruff takes this rule from flake8-self and made it stable in v0.0.240.
- Code
SLF001- Message
Private member accessed: `{}`
In Python, the __slots__ attribute allows you to explicitly define the attributes (instance variables) that a class can have. By default, Python uses a dictionary to store an object's attributes, which incurs some memory overhead. However, when __slots__ is defined, Python uses a more compact internal structure to store the object's attributes, resulting in memory savings. Ruff takes this rule from flake8-slots and made it stable in v0.0.273.
- Code
SLOT000- Message
Subclasses of `str` should define `__slots__`
In Python, the __slots__ attribute allows you to explicitly define the attributes (instance variables) that a class can have. By default, Python uses a dictionary to store an object's attributes, which incurs some memory overhead. However, when __slots__ is defined, Python uses a more compact internal structure to store the object's attributes, resulting in memory savings. Ruff takes this rule from flake8-slots and made it stable in v0.0.273.
- Code
SLOT001- Message
Subclasses of `tuple` should define `__slots__`
In Python, the __slots__ attribute allows you to explicitly define the attributes (instance variables) that a class can have. By default, Python uses a dictionary to store an object's attributes, which incurs some memory overhead. However, when __slots__ is defined, Python uses a more compact internal structure to store the object's attributes, resulting in memory savings. Ruff takes this rule from flake8-slots and made it stable in v0.0.273.
- Code
SLOT002- Message
Subclasses of {} should define `__slots__`
Warn about cases where a bytes object may be converted to a string in an unexpected manner. mypy enables this error code by default.
- Code
str-bytes-safe- Severity
- error
Mypy will check that f-strings, str.format() calls, and % interpolations are valid (when corresponding template is a literal string). This includes checking number and types of replacements, for example. mypy enables this error code by default.
- Code
str-format- Severity
- error
It can sometimes be surprising that str is iterable, especially when unpacking in an assignment. mypy enables this error code by default.
- Code
str-unpack- Severity
- error
If the code being checked is not syntactically valid, mypy issues a syntax error. Most, but not all, syntax errors are *blocking errors*: they can't be ignored with a # type: ignore comment. mypy enables this error code by default.
- Code
syntax- Severity
- error
Debugger calls and imports should be used for debugging purposes only. The presence of a debugger call or import in production code is likely a mistake and may cause unintended behavior, such as exposing sensitive information or causing the program to hang. Ruff takes this rule from flake8-debugger and made it stable in v0.0.141.
- Code
T100- Message
Trace found: `{}` used- Message
Import for `{}` found
print statements used for debugging should be omitted from production code. They can lead the accidental inclusion of sensitive information in logs, and are not configurable by clients, unlike logging statements. Ruff takes this rule from flake8-print and made it stable in v0.0.57.
- Code
T201- Message
`print` found
Like print statements, pprint statements used for debugging should be omitted from production code. They can lead the accidental inclusion of sensitive information in logs, and are not configurable by clients, unlike logging statements. Ruff takes this rule from flake8-print and made it stable in v0.0.57.
- Code
T203- Message
`pprint` found
Imports that are only used for type annotations add a performance overhead at runtime. For first-party imports, they can also contribute to import cycles. If an import is _only_ used in typing-only contexts, it can instead be imported conditionally under an if TYPE_CHECKING: block to minimize runtime overhead. Ruff takes this rule from flake8-type-checking and made it stable in 0.8.0.
- Code
TC001- Message
Move application import `{}` into a type-checking block
Imports that are only used for type annotations add a performance overhead at runtime. If an import is _only_ used in typing-only contexts, it can instead be imported conditionally under an if TYPE_CHECKING: block to minimize runtime overhead. Ruff takes this rule from flake8-type-checking and made it stable in 0.8.0.
- Code
TC002- Message
Move third-party import `{}` into a type-checking block
Imports that are only used for type annotations add a performance overhead at runtime. If an import is _only_ used in typing-only contexts, it can instead be imported conditionally under an if TYPE_CHECKING: block to minimize runtime overhead. Ruff takes this rule from flake8-type-checking and made it stable in 0.8.0.
- Code
TC003- Message
Move standard library import `{}` into a type-checking block
The type-checking block is not executed at runtime, so if the only definition of a symbol is in a type-checking block, it will not be available at runtime. Ruff takes this rule from flake8-type-checking and made it stable in 0.8.0.
- Code
TC004- Message
Move import `{}` out of type-checking block. Import is used for more than type hinting.- Message
Quote references to `{}`. Import is in a type-checking block.
The type-checking block does not do anything and should be removed to avoid confusion. Ruff takes this rule from flake8-type-checking and made it stable in 0.8.0.
- Code
TC005- Message
Found empty type-checking block
This rule helps enforce a consistent style across your codebase. Ruff takes this rule from flake8-type-checking and made it stable in 0.10.0.
- Code
TC006- Message
Add quotes to type expression in `typing.cast()`
Referencing type-checking only symbols results in a NameError at runtime. Ruff takes this rule from flake8-type-checking and made it stable in 0.10.0.
- Code
TC007- Message
Add quotes to type alias
Unnecessary string forward references can lead to additional overhead in runtime libraries making use of type hints. They can also have bad interactions with other runtime uses like PEP 604 type unions. Ruff takes this rule from flake8-type-checking. It is in preview.
- Code
TC008- Message
Remove quotes from type alias
PEP 604 introduced a new syntax for union type annotations based on the | operator. Ruff takes this rule from flake8-type-checking and made it stable in 0.8.0.
- Code
TC010- Message
Invalid string member in `X | Y`-style union type
Ambiguous tags reduce code visibility and can lead to dangling TODOs. For example, if a comment is tagged with "FIXME" rather than "TODO", it may be overlooked by future readers. Ruff takes this rule from flake8-todos and made it stable in v0.0.269.
- Code
TD001- Message
Invalid TODO tag: `{}`
Including an author on a TODO provides future readers with context around the issue. While the TODO author is not always considered responsible for fixing the issue, they are typically the individual with the most context. Ruff takes this rule from flake8-todos and made it stable in v0.0.269.
- Code
TD002- Message
Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...`
Including an issue link near a TODO makes it easier for resolvers to get context around the issue. Ruff takes this rule from flake8-todos and made it stable in v0.0.269.
- Code
TD003- Message
Missing issue link for this TODO
"TODO" tags are typically followed by a parenthesized author name, a colon, a space, and a description of the issue, in that order. Ruff takes this rule from flake8-todos and made it stable in v0.0.269.
- Code
TD004- Message
Missing colon in TODO
TODO comments should include a description of the issue to provide context for future readers. Ruff takes this rule from flake8-todos and made it stable in v0.0.269.
- Code
TD005- Message
Missing issue description after `TODO`
Capitalizing the "TODO" in a TODO comment is a convention that makes it easier for future readers to identify TODOs. Ruff takes this rule from flake8-todos and made it stable in v0.0.269.
- Code
TD006- Message
Invalid TODO capitalization: `{}` should be `TODO`
"TODO" tags are typically followed by a parenthesized author name, a colon, a space, and a description of the issue, in that order. Ruff takes this rule from flake8-todos and made it stable in v0.0.269.
- Code
TD007- Message
Missing space after colon in TODO
Projects may want to ensure that specific modules or module members are not imported or accessed. Ruff takes this rule from flake8-tidy-imports and made it stable in v0.0.201.
- Code
TID251- Message
`{}` is banned: {}
Absolute imports, or relative imports from siblings, are recommended by PEP 8: Ruff takes this rule from flake8-tidy-imports and made it stable in v0.0.169.
- Code
TID252- Message
Prefer absolute imports over relative imports from parent modules- Message
Prefer absolute imports over relative imports
Some modules are expensive to import. For example, importing torch or tensorflow can introduce a noticeable delay in the startup time of a Python program. Ruff takes this rule from flake8-tidy-imports and made it stable in v0.0.285.
- Code
TID253- Message
`{}` is banned at the module level
Python 3.15 adds support for lazy import and lazy from ... import ..., which defer the actual import work until the imported name is first used. Ruff takes this rule from flake8-tidy-imports. It is in preview.
- Code
TID254- Message
`{}` should be imported lazily- Message
Use a `lazy` import instead of an eager import- Message
`{}` should be imported eagerly- Message
Use an eager import instead of a `lazy` import
Python 3.15 adds support for lazy import and lazy from ... import ..., which defer the actual import work until the imported name is first used. Ruff takes this rule from flake8-tidy-imports. It is in preview.
- Code
TID255- Message
Lazy import `{}` is resolved immediately
This error code is separate from the general [syntax] errors, because in some environments (e.g. IPython) a top level await is allowed. mypy enables this error code by default.
- Code
top-level-await- Severity
- error
Warn when the type of an expression in a boolean context does not implement __bool__ or __len__. Unless one of these is implemented by a subtype, the expression will always be considered true, and there may be a bug in the condition. mypy does not enable this error code by default. Use --enable-error-code truthy-bool to enable it.
- Code
truthy-bool- Severity
- error
Functions will always evaluate to true in boolean contexts. mypy enables this error code by default.
- Code
truthy-function- Severity
- error
Generate an error if a value of type Iterable is used as a boolean condition, since Iterable does not implement __len__ or __bool__. mypy does not enable this error code by default. Use --enable-error-code truthy-iterable to enable it.
- Code
truthy-iterable- Severity
- error
Handling such exceptions requires the use of except Exception or except BaseException. These will capture almost _any_ raised exception, including failed assertions, division by zero, and more. Ruff takes this rule from tryceratops and made it stable in v0.0.236.
- Code
TRY002- Message
Create your own exception
By formatting an exception message at the raise site, the exception class becomes less reusable, and may now raise inconsistent messages depending on where it is raised. Ruff takes this rule from tryceratops and made it stable in v0.0.236.
- Code
TRY003- Message
Avoid specifying long messages outside the exception class
The Python documentation states that TypeError should be raised upon encountering an inappropriate type. Ruff takes this rule from tryceratops and made it stable in v0.0.230.
- Code
TRY004- Message
Prefer `TypeError` exception for invalid type
The from keyword sets the __cause__ attribute of the exception, which stores the "cause" of the exception. The availability of an exception "cause" is useful for debugging. Ruff takes this rule from tryceratops, and removed it.
- Code
TRY200- Message
Use `raise from` to specify exception cause
It's redundant to specify the exception name in a raise statement if the exception is being re-raised. Ruff takes this rule from tryceratops and made it stable in v0.0.231.
- Code
TRY201- Message
Use `raise` without specifying exception name
Capturing an exception, only to immediately reraise it, has no effect. Instead, remove the error-handling code and let the exception propagate upwards without the unnecessary try-except block. Ruff takes this rule from tryceratops and made it stable in 0.7.0.
- Code
TRY203- Message
Remove exception handler; error is immediately re-raised
The try-except statement has an else clause for code that should run _only_ if no exceptions were raised. Returns in try blocks may exhibit confusing or unwanted behavior, such as being overridden by control flow in except and finally blocks, or unintentionally suppressing an exception. Ruff takes this rule from tryceratops and made it stable in v0.0.229.
- Code
TRY300- Message
Consider moving this statement to an `else` block
The only raises caught are those that throw exceptions caught by the try statement itself. Raising and catching exceptions within the same try block is redundant, as the code can be refactored to avoid the try block entirely. Ruff takes this rule from tryceratops and made it stable in v0.0.233.
- Code
TRY301- Message
Abstract `raise` to an inner function