Programming Search⌘K

Python lints, page 4 of 8

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

Checks for CamelCase imports that are aliased as acronyms. N817

PEP 8 recommends naming conventions for classes, functions, constants, and more. The use of inconsistent naming styles between import and alias names may lead readers to expect an import to be of another type (e.g., confuse a Python class with a constant). Ruff takes this rule from pep8-naming and made it stable in v0.0.82.

Code
N817
Message
CamelCase `{}` imported as acronym `{}`

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

Check that function does not return Any value. no-any-return

If you use --warn-return-any, mypy generates an error if you return a value with a plain Any type in a function that is annotated to return a non-Any value. You can use this to enforce better boundaries around unsafe/dynamic code. mypy does not enable this error code by default. Use --enable-error-code no-any-return to enable it.

Code
no-any-return
Severity
error

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

Check that types have no Any components due to missing imports. no-any-unimported

If you use --disallow-any-unimported, mypy generates an error if a component of a type becomes Any because mypy couldn't resolve an import. These "stealth" Any types can be surprising and accidentally cause imprecise type checking. mypy does not enable this error code by default. Use --enable-error-code no-any-unimported to enable it.

Code
no-any-unimported
Severity
error

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

Checks for deprecated NumPy type aliases. NPY001

NumPy's np.int has long been an alias of the builtin int; the same is true of np.float and others. These aliases exist primarily for historic reasons, and have been a cause of frequent confusion for newcomers. Ruff takes this rule from NumPy-specific rules and made it stable in v0.0.247.

Code
NPY001
Message
Type alias `np.{}` is deprecated, replace with builtin type

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

Checks for uses of NumPy functions and constants that were removed from the main namespace in NumPy 2.0. NPY201

NumPy 2.0 includes an overhaul of NumPy's Python API, intended to remove redundant aliases and routines, and establish unambiguous mechanisms for accessing constants, dtypes, and functions. Ruff takes this rule from NumPy-specific rules and made it stable in v0.2.0.

Code
NPY201
Message
`np.{}` will be removed in NumPy 2.0. {}
Message
`np.{}` will be removed without replacement in NumPy 2.0

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

Check for overload signatures that cannot match. overload-cannot-match

Warn if an @overload variant can never be matched, because an earlier overload has a wider signature. For example, this can happen if the two overloads accept the same parameters and each parameter on the first overload has the same type or a wider type than the corresponding parameter on the second overload. mypy enables this error code by default.

Code
overload-cannot-match
Severity
error

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

Check validity of overrides. override

Mypy checks that an overridden method or attribute is compatible with the base class. A method in a subclass must accept all arguments that the base class method accepts, and the return type must conform to the return type in the base class (Liskov substitution principle). mypy enables this error code by default.

Code
override
Severity
error

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

Checks for inplace=True usages in pandas function and method calls. PD002

Using inplace=True encourages mutation rather than immutable data, which is harder to reason about and may cause bugs. It also removes the ability to use the method chaining style for pandas operations. Ruff takes this rule from pandas-vet and made it stable in v0.0.188.

Code
PD002
Message
`inplace=True` should be avoided; it has inconsistent behavior

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

Checks for uses of .at on Pandas objects. PD008

The .at method selects a single value from a DataFrame or Series based on a label index, and is slightly faster than using .loc. However, .loc is more idiomatic and versatile, as it can be used to select multiple values at once. Ruff takes this rule from pandas-vet and made it stable in v0.0.188.

Code
PD008
Message
Use `.loc` instead of `.at`. If speed is important, use NumPy.

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

Checks for uses of .iat on Pandas objects. PD009

The .iat method selects a single value from a DataFrame or Series based on an ordinal index, and is slightly faster than using .iloc. However, .iloc is more idiomatic and versatile, as it can be used to select multiple values at once. Ruff takes this rule from pandas-vet and made it stable in v0.0.188.

Code
PD009
Message
Use `.iloc` instead of `.iat`. If speed is important, use NumPy.

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

Checks for uses of pd.read_table to read CSV files. PD012

In the Pandas API, pd.read_csv and pd.read_table are equivalent apart from their default separator: pd.read_csv defaults to a comma (,), while pd.read_table defaults to a tab (\t) as the default separator. Ruff takes this rule from pandas-vet and made it stable in v0.0.188.

Code
PD012
Message
Use `.read_csv` instead of `.read_table` to read CSV files

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

Checks for uses of dict.items() that discard either the key or the value when iterating over the dictionary. PERF102

If you only need the keys or values of a dictionary, you should use dict.keys() or dict.values() respectively, instead of dict.items(). These specialized methods are more efficient than dict.items(), as they avoid allocating tuples for every item in the dictionary. They also communicate the intent of the code more clearly. Ruff takes this rule from Perflint and made it stable in v0.0.273.

Code
PERF102
Message
When using only the {} of a dict use the `{}()` method

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

Checks for for loops that append every item of an iterable to a list, which can be replaced with a call to list. PERF402

When populating a list from an iterable with a for loop, prefer list instead. The list call is more readable and more performant. For an existing list, you can also use list.copy instead of list. Ruff takes this rule from Perflint and made it stable in v0.0.276.

Code
PERF402
Message
Use `list` or `list.copy` to create a copy of a list

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

Checks for unnecessary pass statements and ellipsis (...) literals in functions, classes, and other blocks. PIE790

In Python, the pass statement and ellipsis (...) literal serve as placeholders, allowing for syntactically correct empty code blocks. The primary purpose of these nodes is to avoid syntax errors in situations where a statement or expression is syntactically required, but no code needs to be executed. Ruff takes this rule from flake8-pie and made it stable in v0.0.208.

Code
PIE790
Message
Unnecessary `pass` statement
Message
Unnecessary `...` literal

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

Checks for unnecessary dict kwargs. PIE804

If the dict keys are valid identifiers, they can be passed as keyword arguments directly, without constructing unnecessary dictionary. This also makes code more type-safe as type checkers often cannot precisely verify dynamic keyword arguments. Ruff takes this rule from flake8-pie and made it stable in v0.0.231.

Code
PIE804
Message
Unnecessary `dict` kwargs

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

Checks for type names that do not match the variance of their associated type parameter. PLC0105

PEP 484 recommends the use of the _co and _contra suffixes for covariant and contravariant type parameters, respectively (while invariant type parameters should not have any such suffix). Ruff takes this rule from Pylint and made it stable in v0.0.278.

Code
PLC0105
Message
`{}` name "{}" does not reflect its {}; consider renaming it to "{}"

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

Checks for TypeVar and ParamSpec definitions in which the type is both covariant and contravariant. PLC0131

By default, Python's generic types are invariant, but can be marked as either covariant or contravariant via the covariant and contravariant keyword arguments. While the API does allow you to mark a type as both covariant and contravariant, this is not supported by the type system, and should be avoided. Ruff takes this rule from Pylint and made it stable in v0.0.278.

Code
PLC0131
Message
`{}` cannot be both covariant and contravariant
Message
`{}` "{}" cannot be both covariant and contravariant

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

Checks for TypeVar, TypeVarTuple, ParamSpec, and NewType definitions in which the name of the type parameter does not match the name of the variable to which it is assigned. PLC0132

When defining a TypeVar or a related type parameter, Python allows you to provide a name for the type parameter. According to PEP 484, the name provided to the TypeVar constructor must be equal to the name of the variable to which it is assigned. Ruff takes this rule from Pylint and made it stable in v0.0.277.

Code
PLC0132
Message
`{}` name `{}` does not match assigned variable name `{}`

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

Checks for single strings assigned to __slots__. PLC0205

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 Pylint and made it stable in v0.0.276.

Code
PLC0205
Message
Class `__slots__` should be a non-string iterable

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

Checks for access to the first or last element of str.split() or str.rsplit() without a maxsplit=1 argument. PLC0207

Calling str.split() or str.rsplit() without passing maxsplit=1 splits on every delimiter in the string. When accessing only the first or last element of the result, it would be more efficient to split only once. Ruff takes this rule from Pylint and made it stable in 0.15.0.

Code
PLC0207
Message
String is split more times than necessary

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

Checks for import statements outside of a module's top-level scope, such as within a function or class definition. PLC0415

PEP 8 recommends placing imports not only at the top-level of a module, but at the very top of the file, "just after any module comments and docstrings, and before module globals and constants." Ruff takes this rule from Pylint and made it stable in 0.12.0.

Code
PLC0415
Message
`import` should be at the top-level of a file

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

Checks for comparisons to empty strings. PLC1901

An empty string is falsy, so it is unnecessary to compare it to "". If the value can be something else Python considers falsy, such as None, 0, or another empty container, then the code is not equivalent. Ruff takes this rule from Pylint. It is in preview.

Code
PLC1901
Message
`{}` can be simplified to `{}` as an empty string is falsey

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

Checks for import statements that import a private name (a name starting with an underscore _) from another module. PLC2701

PEP 8 states that names starting with an underscore are private. Thus, they are not intended to be used outside of the module in which they are defined. Ruff takes this rule from Pylint. It is in preview.

Code
PLC2701
Message
Private name import `{}` from external module `{}`
Message
Private name import `{}`

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

Checks for "special" methods that have an unexpected method signature. PLE0302

"Special" methods, like __len__, are expected to adhere to a specific, standard function signature. Implementing a "special" method using a non-standard function signature can lead to unexpected and surprising behavior for users of a given class. Ruff takes this rule from Pylint and made it stable in v0.0.263.

Code
PLE0302
Message
The special method `{}` expects {}, {} {} given

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

Checks for hard-coded sequence accesses that are known to be out of bounds. PLE0643

Attempting to access a sequence with an out-of-bounds index will cause an IndexError to be raised at runtime. When the sequence and index are defined statically (e.g., subscripts on list and tuple literals, with integer indexes), such errors can be detected ahead of time. Ruff takes this rule from Pylint and made it stable in 0.5.0.

Code
PLE0643
Message
Expression is likely to raise `IndexError`

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

Checks duplicate characters in str.strip calls. PLE1310

All characters in str.strip calls are removed from both the leading and trailing ends of the string. Including duplicate characters in the call is redundant and often indicative of a mistake. Ruff takes this rule from Pylint and made it stable in v0.0.242.

Code
PLE1310
Message
String `{}` call contains duplicate characters (did you mean `{}`?)
Message
String `{}` call contains duplicate characters

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

Checks for comparisons between constants. PLR0133

Comparing two constants will always resolve to the same value, so the comparison is redundant. Instead, the expression should be replaced with the result of the comparison. Ruff takes this rule from Pylint and made it stable in v0.0.221.

Code
PLR0133
Message
Two constants compared in a comparison, consider replacing `{} {} {}`

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

Checks for function definitions that include too many arguments. PLR0913

Functions with many arguments are harder to understand, maintain, and call. Consider refactoring functions with many arguments into smaller functions with fewer arguments, or using objects to group related arguments. Ruff takes this rule from Pylint and made it stable in v0.0.238.

Code
PLR0913
Message
Too many arguments in function definition ({} > {})

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

Checks for function definitions that include too many positional arguments. PLR0917

Functions with many arguments are harder to understand, maintain, and call. This is especially true for functions with many positional arguments, as providing arguments positionally is more error-prone and less clear to readers than providing arguments by name. Ruff takes this rule from Pylint and made it stable in 0.16.0.

Code
PLR0917
Message
Too many positional arguments ({} > {})

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

Checks for variables defined in for, try, with statements that redefine function parameters. PLR1704

Redefined variables can cause unexpected behavior because of overridden function parameters. If nested functions are declared, an inner function's body can override an outer function's parameters. Ruff takes this rule from Pylint and made it stable in 0.5.0.

Code
PLR1704
Message
Redefining argument with the local name `{}`

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

Checks for repeated equality comparisons that can be rewritten as a membership test. PLR1714

To check if a variable is equal to one of many values, it is common to write a series of equality comparisons (e.g., foo == "bar" or foo == "baz"). Ruff takes this rule from Pylint and made it stable in v0.0.279.

Code
PLR1714
Message
Consider merging multiple comparisons: `{}`. Use a `set` if the elements are hashable.
Message
Consider merging multiple comparisons: `{}`.
Message
Consider merging multiple comparisons. Use a `set` if the elements are hashable.
Message
Consider merging multiple comparisons.

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

Checks for uses of the exit() and quit(). PLR1722

exit and quit come from the site module, which is typically imported automatically during startup. However, it is not _guaranteed_ to be imported, and so using these functions may result in a NameError at runtime. Generally, these constants are intended to be used in an interactive interpreter, and not in programs. Ruff takes this rule from Pylint and made it stable in v0.0.156.

Code
PLR1722
Message
Use `sys.exit()` instead of `{}`

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

Checks for if statements that can be replaced with min() or max() calls. PLR1730

An if statement that selects the lesser or greater of two sub-expressions can be replaced with a min() or max() call respectively. Where possible, prefer min() and max(), as they're more concise and readable than the equivalent if statements. Ruff takes this rule from Pylint and made it stable in 0.6.0.

Code
PLR1730
Message
Replace `if` statement with `{}`
Message
Replace `if` statement with `{}` call

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

Checks for the use of unnamed numerical constants ("magic") values in comparisons. PLR2004

The use of "magic" values can make code harder to read and maintain, as readers will have to infer the meaning of the value from the context. Such values are discouraged by PEP 8. Ruff takes this rule from Pylint and made it stable in v0.0.221.

Code
PLR2004
Message
Magic value used in comparison, consider replacing `{}` with a constant variable

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

Checks for assignments that can be replaced with augmented assignment statements. PLR6104

If the right-hand side of an assignment statement consists of a binary operation in which one operand is the same as the assignment target, it can be rewritten as an augmented assignment. For example, x = x + 1 can be rewritten as x += 1. Ruff takes this rule from Pylint. It is in preview.

Code
PLR6104
Message
Use `{}` to perform an augmented assignment directly

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

Checks for lambda definitions that consist of a single function call with the same arguments as the lambda itself. PLW0108

When a lambda is used to wrap a function call, and merely propagates the lambda arguments to that function, it can typically be replaced with the function itself, removing a level of indirection. Ruff takes this rule from Pylint and made it stable in 0.15.0.

Code
PLW0108
Message
Lambda may be unnecessary; consider inlining inner function

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

Checks for assert statements that use a string literal as the first argument. PLW0129

An assert on a non-empty string literal will always pass, while an assert on an empty string literal will always fail. Ruff takes this rule from Pylint and made it stable in v0.0.258.

Code
PLW0129
Message
Asserting on an empty string literal will never pass
Message
Asserting on a non-empty string literal will always pass
Message
Asserting on a string literal may have unintended results

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

Checks for uses of named expressions (e.g., a := 42) that can be replaced by regular assignment statements (e.g., a = 42). PLW0131

While a top-level named expression is syntactically and semantically valid, it's less clear than a regular assignment statement. Named expressions are intended to be used in comprehensions and generator expressions, where assignment statements are not allowed. Ruff takes this rule from Pylint and made it stable in v0.0.270.

Code
PLW0131
Message
Named expression used without context

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

Checks for comparisons against NaN values. PLW0177

Comparing against a NaN value can lead to unexpected results. For example, float("NaN") == float("NaN") will return False and, in general, x == float("NaN") will always return False, even if x is NaN. Ruff takes this rule from Pylint and made it stable in 0.12.0.

Code
PLW0177
Message
Comparing against a NaN value; use `math.isnan` instead
Message
Comparing against a NaN value; use `np.isnan` instead

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

Checks for static methods that use self or cls as their first argument. PLW0211

This rule also applies to __new__ methods, which are implicitly static. PEP 8 recommends the use of self and cls as the first arguments for instance methods and class methods, respectively. Naming the first argument of a static method as self or cls can be misleading, as static methods do not receive an instance or class reference as their first argument. Ruff takes this rule from Pylint and made it stable in 0.6.0.

Code
PLW0211
Message
First argument of a static method should not be named `{}`

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

Detects attempts to use super without parentheses. PLW0245

The super() callable can be used inside method definitions to create a proxy object that delegates attribute access to a superclass of the current class. Attempting to access attributes on super itself, however, instead of the object returned by a call to super(), will raise AttributeError. Ruff takes this rule from Pylint and made it stable in 0.5.0.

Code
PLW0245
Message
`super` call is missing parentheses

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

Checks for assignment of self and cls in instance and class methods respectively. PLW0642

The identifiers self and cls are conventional in Python for the first parameter of instance methods and class methods, respectively. Assigning new values to these variables can be confusing for others reading your code; using a different variable name can lead to clearer code. Ruff takes this rule from Pylint and made it stable in 0.6.0.

Code
PLW0642
Message
Reassigned `{}` variable in {} method

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

Checks for except clauses that attempt to catch multiple exceptions with a binary operation (and or or). PLW0711

A binary operation will not catch multiple exceptions. Instead, the binary operation will be evaluated first, and the result of _that_ operation will be caught (for an or operation, this is typically the first exception in the list). This is almost never the desired behavior. Ruff takes this rule from Pylint and made it stable in v0.0.258.

Code
PLW0711
Message
Exception to catch is the result of a binary `and` operation
Message
Exception to catch is the result of a binary `or` operation

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

Check for shallow os.environ copies. PLW1507

os.environ is not a dict object, but rather, a proxy object. As such, mutating a shallow copy of os.environ will also mutate the original object. Ruff takes this rule from Pylint and made it stable in 0.10.0.

Code
PLW1507
Message
Shallow copy of `os.environ` via `copy.copy(os.environ)`

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

Checks for uses of open and related calls without an explicit encoding argument. PLW1514

Using open in text mode without an explicit encoding can lead to non-portable code, with differing behavior across platforms. While readers may assume that UTF-8 is the default encoding, in reality, the default is locale-specific. Ruff takes this rule from Pylint. It is in preview.

Code
PLW1514
Message
`{}` in text mode without explicit `encoding` argument
Message
`{}` without explicit `encoding` argument

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

Checks for classes that implement __eq__ but not __hash__. PLW1641

A class that implements __eq__ but not __hash__ will have its hash method implicitly set to None, regardless of if a superclass defines __hash__. This will cause the class to be unhashable, which will in turn cause issues when using instances of the class as keys in a dictionary or members of a set. Ruff takes this rule from Pylint and made it stable in 0.12.0.

Code
PLW1641
Message
Object does not implement `__hash__` method

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

Checks for variables defined in for loops and with statements that get overwritten within the body, for example by another for loop or with statement or by direct assignment. PLW2901

Redefinition of a loop variable inside the loop's body causes its value to differ from the original loop iteration for the remainder of the block, in a way that will likely cause bugs. Ruff takes this rule from Pylint and made it stable in v0.0.252.

Code
PLW2901
Message
Outer {} variable `{}` overwritten by inner {} target
Message
{} variable `{}` overwritten by {} target

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

Warn about variables that are defined only in some execution paths. possibly-undefined

If you use --enable-error-code possibly-undefined, mypy generates an error if it cannot verify that a variable will be defined in all execution paths. This includes situations when a variable definition appears in a loop, in a conditional branch, in an except handler, etc. mypy does not enable this error code by default. Use --enable-error-code possibly-undefined to enable it.

Code
possibly-undefined
Severity
error

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

Checks for the type of parameter names passed to pytest.mark.parametrize. PT006

The argnames argument of pytest.mark.parametrize takes a string or a sequence of strings. For a single parameter, it's preferable to use a string. For multiple parameters, it's preferable to use the style configured via the lint.flake8-pytest-style.parametrize-names-type setting. Ruff takes this rule from flake8-pytest-style and made it stable in v0.0.208.

Code
PT006
Message
Wrong type passed to first argument of `pytest.mark.parametrize`; expected {}

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

Checks for the type of parameter values passed to pytest.mark.parametrize. PT007

The argvalues argument of pytest.mark.parametrize takes an iterator of parameter values, which can be provided as lists or tuples. Ruff takes this rule from flake8-pytest-style and made it stable in v0.0.208.

Code
PT007
Message
Wrong values type in `pytest.mark.parametrize` expected `{}`
Message
Wrong values type in `pytest.mark.parametrize` expected `{}` of `{}`

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

Checks for pytest.raises calls without an expected exception. PT010

pytest.raises expects to receive an expected exception as its first argument. If omitted, the pytest.raises call will fail at runtime. The rule will also accept calls without an expected exception but with match and/or check keyword arguments, which are also valid after pytest version 8.4.0. Ruff takes this rule from flake8-pytest-style and made it stable in v0.0.208.

Code
PT010
Message
Set the expected exception in `pytest.raises()`

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

Checks for pytest.raises calls without a match or check parameter. PT011

pytest.raises(Error) will catch any Error and may catch errors that are unrelated to the code under test. To avoid this, pytest.raises should be called with a match parameter (to constrain the exception message) or a check parameter (to constrain the exception itself). The exception names that require a match or check parameter can be configured via the lint.flake8-pytest-style.raises-require-match-for and lint.flake8-pytest-style.raises-extend-require-match-for settings. Ruff takes this rule from flake8-pytest-style and made it stable in v0.0.208.

Code
PT011
Message
`pytest.raises({})` is too broad, set the `match` parameter or use a more specific exception

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

Checks for incorrect import of pytest. PT013

For consistency, pytest should be imported as import pytest and its members should be accessed in the form of pytest.xxx.yyy for consistency Ruff takes this rule from flake8-pytest-style and made it stable in v0.0.208.

Code
PT013
Message
Incorrect import of `pytest`; use `import pytest` instead

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

Checks for assert statements in except clauses. PT017

When testing for exceptions, pytest.raises() should be used instead of assert statements in except clauses, as it's more explicit and idiomatic. Further, pytest.raises() will fail if the exception is _not_ raised, unlike the assert statement. Ruff takes this rule from flake8-pytest-style and made it stable in v0.0.208.

Code
PT017
Message
Found assertion on exception `{}` in `except` block, use `pytest.raises()` instead

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