Programming Search⌘K

Python lints, page 6 of 8

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

Checks for uses of assert expression, print(message). RUF030

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

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

Checks for Decimal calls passing a float literal. RUF032

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

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

Checks for __post_init__ dataclass methods with parameter defaults. RUF033

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

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

Checks for type annotations where None is not at the end of a union. RUF036

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.

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

Checks for LiteralTrue, False type annotations. RUF038

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`

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

Checks for non-raw literal string arguments passed to the match parameter of pytest.raises() where the string contains at least one unescaped regex metacharacter. RUF043

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

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

Checks for implicit class variables in dataclasses. RUF045

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

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

Checks for if statements (without elif or else branches) where the body contains only pass or ... RUF050

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

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

Checks for "dummy variables" (variables that are named as if to indicate they are unused) that are in fact used. RUF052

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

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

Checks for uses of foo.__dict__.get("__annotations__") or foo.__dict__"__annotations__" on Python 3.10+ and Python < 3.10 when lint.typing-extensions is enabled. RUF063

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

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

Checks for eager string conversion of arguments to logging calls. RUF065

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`

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

Detects the presence of code in __init__.py files. RUF067

__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

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

Checks for comparisons between floating-point values using == or !=. RUF069

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 `{} {} {}`

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

Checks for variable assignments that immediately precede a yield (or yield from) of the assigned variable, where the variable is not referenced anywhere else. RUF070

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

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

Checks for uses of os.path.commonprefix. RUF071

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

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

Checks for uses of the % operator on f-strings. RUF073

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

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

Checks for incorrect ordering of decorators on functions and methods. RUF074

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 `@{}`

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

Checks for @contextlib.contextmanager decorated functions that contain yield expressions not protected against exceptions. RUF075

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

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

Checks for noqa directives that use redirected rule codes. RUF101

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 `{}`

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

Checks for uses of the assert keyword. S101

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

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

Checks for the use of hardcoded temporary file or directory paths. S108

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: "{}"

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

Checks for uses of the try-except-pass pattern. S110

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

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

Checks for uses of the try-except-continue pattern. S112

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

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

Checks for uses of the Python requests or httpx module that omit the timeout parameter. S113

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`

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

Checks for uses of debug=True in Flask. S201

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

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

Checks for uses of tarfile.extractall. S202

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()`

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

Checks for calls to pickle functions or modules that wrap them. S301

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

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

Checks for calls to marshal functions. S302

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

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

Checks for uses of weak or broken cryptographic hash functions. S303

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

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

Checks for uses of weak or broken cryptographic ciphers. S304

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

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

Checks for uses of weak or broken cryptographic cipher modes. S305

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

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

Checks for uses of tempfile.mktemp. S306

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`)

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

Checks for uses of calls to django.utils.safestring.mark_safe. S308

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

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

Checks for instances where URL open functions are used with unexpected schemes. S310

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.

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

Checks for uses of cryptographically weak pseudo-random number generators. S311

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

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

Checks for uses of insecure XML parsers. S313

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

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

Checks for uses of insecure XML parsers. S314

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

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

Checks for uses of insecure XML parsers. S315

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

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

Checks for uses of insecure XML parsers. S316

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

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

Checks for uses of insecure XML parsers. S317

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

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

Checks for uses of insecure XML parsers. S318

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

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

Checks for uses of insecure XML parsers. S319

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

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

Checks for uses of insecure XML parsers. S320

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

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

Checks for the use of FTP-related functions. S321

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.

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

Checks for uses of ssl._create_unverified_context. S323

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.

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

Checks for uses of weak or broken cryptographic hash functions in hashlib and crypt libraries. S324

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 `{}`: `{}`

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

Checks for imports of the telnetlib module. S401

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.

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

Checks for imports of the xml.etree.cElementTree and xml.etree.ElementTree modules. S405

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

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

Checks for imports of the xml.sax module. S406

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

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

Checks for imports of the xml.dom.expatbuilder module. S407

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

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

Checks for imports of the xml.dom.minidom module. S408

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

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

Checks for imports of the xml.dom.pulldom module. S409

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

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

Checks for imports of the xmlrpc module. S411

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

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

Checks for imports of wsgiref.handlers.CGIHandler and twisted.web.twcgi.CGIScript. S412

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

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

Checks for function calls with parameters that indicate the use of insecure SSL and TLS protocol versions. S502

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: `{}`

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

Checks for function definitions with default arguments set to insecure SSL and TLS protocol versions. S503

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: `{}`

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

Checks for uses of the yaml.load function. S506

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`.

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

Checks for uses of policies disabling SSH verification in Paramiko. S507

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

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

Checks for uses of SNMPv1 or SNMPv2. S508

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.

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

Checks for paramiko calls. S601

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

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

Check for method calls that initiate a subprocess with a shell. S602

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

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

Checks for method calls that set the shell parameter to true or another truthy value when invoking a subprocess. S604

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

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

Checks for calls that start a process with a shell, providing guidance on whether the usage is safe or not. S605

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

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

Checks for strings that resemble SQL statements involved in some form string building operation. S608

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

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

Checks for insecure logging.config.listen calls. S612

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

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

Checks for jinja2 templates that use autoescape=False. S701

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.

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

Checks for uses of the mako templates. S702

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

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

Checks for multiple isinstance calls on the same target. SIM101

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

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

Check for if-else-blocks that can be replaced with a ternary or binary operator. SIM108

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

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

Checks for for loops with explicit loop-index variables that can be replaced with enumerate(). SIM113

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

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

Checks for cases where files are opened (e.g., using the builtin open() function) without using a context manager. SIM115

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

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

Checks for if expressions that can be replaced with bool() calls. SIM210

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`

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

Checks for conditions that position a constant on the left-hand side of the comparison operator, rather than the right-hand side. SIM300

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

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

Checks for if statements that can be replaced with dict.get calls. SIM401

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

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

Checks for accesses on "private" class members. SLF001

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: `{}`

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

Checks for subclasses of str that lack a __slots__ definition. SLOT000

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__`

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

Checks for subclasses of tuple that lack a __slots__ definition. SLOT001

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__`

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

Checks for subclasses of collections.namedtuple or typing.NamedTuple that lack a __slots__ definition. SLOT002

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__`

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

Checks for the presence of debugger calls and imports. T100

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

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

Checks for print statements. T201

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

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

Checks for pprint statements. T203

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

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

Checks for first-party imports that are only used for type annotations, but aren't defined in a type-checking block. TC001

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

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

Checks for third-party imports that are only used for type annotations, but aren't defined in a type-checking block. TC002

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

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

Checks for standard library imports that are only used for type annotations, but aren't defined in a type-checking block. TC003

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

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

Checks for imports that are required at runtime but are only defined in type-checking blocks. TC004

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.

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

Checks that a TODO comment includes an author. TD002

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>: ...`

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

Checks for relative imports. TID252

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

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

Checks for module-level imports that should instead be imported lazily (e.g., within a function definition, or an if TYPE_CHECKING: block, or some other nested context). TID253

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

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

Enforces the configured lazy-import policy in contexts where lazy import is legal. TID254

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

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

Check that expression is not implicitly true in boolean context. truthy-bool

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

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

Checks for return statements in try blocks. TRY300

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

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

Checks for raise statements within try blocks. TRY301

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

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