Programming Search⌘K

Python lints, page 7 of 8

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

Checks for uses of logging.error instead of logging.exception when logging an exception. TRY400

logging.exception logs the exception and the traceback, while logging.error only logs the exception. The former is more appropriate when logging an exception, as the traceback is often useful for debugging. Ruff takes this rule from tryceratops and made it stable in v0.0.236.

Code
TRY400
Message
Use `logging.exception` instead of `logging.error`

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

Checks for excessive logging of exception objects. TRY401

When logging exceptions via logging.exception, the exception object is logged automatically. Including the exception object in the log message is redundant and can lead to excessive logging. Ruff takes this rule from tryceratops and made it stable in v0.0.250.

Code
TRY401
Message
Redundant exception object included in `logging.exception` call

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

Safe handling of abstract type object types. type-abstract

Mypy always allows instantiating (calling) type objects typed as type[t], even if it is not known that t is non-abstract, since it is a common pattern to create functions that act as object factories (custom constructors). Therefore, to prevent issues described in the above section, when an abstract type object is passed where type[t] is expected, mypy will give an error. mypy enables this error code by default.

Code
type-abstract
Severity
error

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

Check TypedDict Keys. typeddict-unknown-key

When constructing a TypedDict object, mypy checks whether the definition contains unknown keys, to catch invalid keys and misspellings. On the other hand, mypy will not generate an error when a previously constructed TypedDict value with extra keys is passed to a function as an argument, since TypedDict values support structural subtyping ("static duck typing") and the keys are assumed to have been validated at the point of construction. mypy enables this error code by default.

Code
typeddict-unknown-key
Severity
error

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

Check that reveal_type is imported from typing or typing_extensions. unimported-reveal

Mypy used to have reveal_type as a special builtin that only existed during type-checking. In runtime it fails with expected NameError, which can cause real problem in production, hidden from mypy. mypy does not enable this error code by default. Use --enable-error-code unimported-reveal to enable it.

Code
unimported-reveal
Severity
error

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

Check that statement or expression is unreachable. unreachable

If you use --warn-unreachable, mypy generates an error if it thinks that a statement or expression will never be executed. In most cases, this is due to incorrect control flow or conditional checks that are accidentally always true or false. mypy does not enable this error code by default. Use --enable-error-code unreachable to enable it.

Code
unreachable
Severity
error

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

Error if an untyped decorator makes a typed function effectively untyped. untyped-decorator

If enabled with --disallow-untyped-decorators mypy generates an error if a typed function is wrapped by an untyped decorator (as this would effectively remove the benefits of typing the function). mypy does not enable this error code by default. Use --enable-error-code untyped-decorator to enable it.

Code
untyped-decorator
Severity
error

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

Check that # type: ignore comment is used. unused-ignore

If you use --enable-error-code unused-ignore, or --warn-unused-ignores mypy generates an error if you don't use a # type: ignore comment, i.e. if there is a comment, but there would be no error generated by mypy on this line anyway. mypy does not enable this error code by default. Use --enable-error-code unused-ignore to enable it.

Code
unused-ignore
Severity
error

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

Checks for the use of generics that can be replaced with standard library variants based on PEP 585. UP006

PEP 585 enabled collections in the Python standard library (like list) to be used as generics directly, instead of importing analogous members from the typing module (like typing.List). Ruff takes this rule from pyupgrade and made it stable in v0.0.155.

Code
UP006
Message
Use `{}` instead of `{}` for type annotation

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

Checks for unnecessary __future__ imports. UP010

The __future__ module is used to enable features that are not yet available in the current Python version. If a feature is already available in the minimum supported Python version, importing it from __future__ is unnecessary and should be removed to avoid confusion. Ruff takes this rule from pyupgrade and made it stable in v0.0.155.

Code
UP010
Message
Unnecessary `__future__` import `{}` for target Python version
Message
Unnecessary `__future__` imports {} for target Python version

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

Checks for uses of subprocess.run that set the universal_newlines keyword argument. UP021

As of Python 3.7, the universal_newlines keyword argument has been renamed to text, and now exists for backwards compatibility. The universal_newlines keyword argument may be removed in a future version of Python. Prefer text, which is more explicit and readable. Ruff takes this rule from pyupgrade and made it stable in v0.0.196.

Code
UP021
Message
`universal_newlines` is deprecated, use `text`

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

Checks for uses of subprocess.run that send stdout and stderr to a pipe. UP022

As of Python 3.7, subprocess.run has a capture_output keyword argument that can be set to True to capture stdout and stderr outputs. This is equivalent to setting stdout and stderr to subprocess.PIPE, but is more explicit and readable. Ruff takes this rule from pyupgrade and made it stable in v0.0.199.

Code
UP022
Message
Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`

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

Checks for printf-style string formatting, and offers to replace it with str.format calls. UP031

printf-style string formatting has a number of quirks, and leads to less readable code than using str.format calls or f-strings. In general, prefer the newer str.format and f-strings constructs over printf-style string formatting. Ruff takes this rule from pyupgrade and made it stable in v0.0.229.

Code
UP031
Message
Use format specifiers instead of percent format

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

Checks for conditional blocks gated on sys.version_info comparisons that are outdated for the minimum supported Python version. UP036

In Python, code can be conditionally executed based on the active Python version by comparing against the sys.version_info tuple. Ruff takes this rule from pyupgrade and made it stable in v0.0.240.

Code
UP036
Message
Version block is outdated for minimum Python version
Message
Version specifier is invalid

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

Checks for unnecessary default type arguments for Generator and AsyncGenerator on Python 3.13+. UP043

Python 3.13 introduced the ability for type parameters to specify default values. Following this change, several standard-library classes were updated to add default values for some of their type parameters. For example, Generatorint is now equivalent to Generatorint, None, None, as the second and third type parameters of Generator now default to None. Ruff takes this rule from pyupgrade and made it stable in 0.8.0.

Code
UP043
Message
Unnecessary default type arguments

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

Checks for use of standalone type variables and parameter specifications in generic classes. UP046

Special type parameter syntax was introduced in Python 3.12 by PEP 695 for defining generic classes. This syntax is easier to read and provides cleaner support for generics. Ruff takes this rule from pyupgrade and made it stable in 0.12.0.

Code
UP046
Message
Generic class `{}` uses `Generic` subclass instead of type parameters

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

Checks for while loops that use 1 as their condition. UP048

while 1: is a Python 2 idiom, where True was a global that could be rebound and so had to be loaded and tested on every iteration. In Python 3 True is a keyword, so both spellings compile to the same bytecode and while True: is clearer about the loop being infinite. Ruff takes this rule from pyupgrade. It is in preview.

Code
UP048
Message
Use `while True:` instead of `while 1:`

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

Check that a variable is not used before it's defined. used-before-def

Mypy will generate an error if a name is used before it's defined. While the name-defined check will catch issues with names that are undefined, it will not flag if a variable is used and then defined later in the scope. used-before-def check will catch such cases. mypy enables this error code by default.

Code
used-before-def
Severity
error

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

String statement has no effect. W0105

Used when a string is used as a statement (which of course has no effect). This is a particular case of W0104 with its own message so you can easily disable it if you're using those strings as documentation, instead of comments. pylint calls it pointless-string-statement.

Code
W0105
Severity
warning
Message
String statement has no effect

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

Lambda may not be necessary. W0108

Used when the body of a lambda expression is a function call on the same argument list as the lambda itself; such lambda expressions are in all but a few cases replaceable with the function being called in the body of the lambda. pylint calls it unnecessary-lambda.

Code
W0108
Severity
warning
Message
Lambda may not be necessary

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

Else clause on loop without a break statement, remove the else and de-indent all the code inside it. W0120

Loops should only have an else clause if they can exit early with a break statement, otherwise the statements under else should be on the same scope as the loop itself. pylint calls it useless-else-on-loop.

Code
W0120
Severity
warning
Message
Else clause on loop without a break statement, remove the else and de-indent all the code inside it

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

Use of exec. W0122

Raised when the 'exec' statement is used. It's dangerous to use this function for a user input, and it's also slower than actual code in general. This doesn't mean you should never use it, but you should consider alternatives first and restrict the functions available. pylint calls it exec-used.

Code
W0122
Severity
warning
Message
Use of exec

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

Use of eval. W0123

Used when you use the "eval" function, to discourage its usage. Consider using ast.literal_eval for safely evaluating strings containing Python expressions from untrusted sources. pylint calls it eval-used.

Code
W0123
Severity
warning
Message
Use of eval

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

Following "as" with another context manager looks like a tuple. W0124

Emitted when a with statement component returns multiple values and uses name binding with as only for a part of those values, as in with ctx() as a, b. This can be misleading, since it's not clear if the context manager returns a tuple or if the node without a name binding is another context manager. pylint calls it confusing-with-statement.

Code
W0124
Severity
warning
Message
Following "as" with another context manager looks like a tuple.

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

Using a conditional statement with potentially wrong function or method call due to missing parentheses. W0126

Emitted when a conditional statement (If or ternary if) seems to wrongly call a function due to missing parentheses. pylint calls it missing-parentheses-for-call-in-test.

Code
W0126
Severity
warning
Message
Using a conditional statement with potentially wrong function or method call due to missing parentheses

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

Checks for doc lines that exceed the specified maximum character length. W505

For flowing long blocks of text (docstrings or comments), overlong lines can hurt readability. PEP 8, for example, recommends that such lines be limited to 72 characters, while this rule enforces the limit specified by the lint.pycodestyle.max-doc-length setting. (If no value is provided, this rule will be ignored, even if it's added to your --select list.) Ruff takes this rule from pycodestyle and made it stable in v0.0.219.

Code
W505
Message
Doc line too long ({} > {})

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

No exception type(s) specified. W0702

A bare except: clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to except BaseException:). pylint calls it bare-except.

Code
W0702
Severity
warning
Message
No exception type(s) specified

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

Consider explicitly re-raising using …'… from …'. W0707

Python's exception chaining shows the traceback of the current exception, but also of the original exception. When you raise a new exception after another exception was caught it's likely that the second exception is a friendly re-wrapping of the first exception. In such cases raise from provides a better link between the two tracebacks in the final error. pylint calls it raise-missing-from.

Code
W0707
Severity
warning
Message
Consider explicitly re-raising using {}'{} from {}'

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

Raising too general exception: …. W0719

Raising exceptions that are too generic force you to catch exceptions generically too. It will force you to use a naked except Exception: clause. You might then end up catching exceptions other than the ones you expect to catch. This can hide bugs or make it harder to debug programs when unrelated errors are hidden. pylint calls it broad-exception-raised.

Code
W0719
Severity
warning
Message
Raising too general exception: {}

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

Keyword argument before variable positional arguments list in the definition of … function. W1113

When defining a keyword argument before variable positional arguments, one can end up in having multiple values passed for the aforementioned parameter in case the method is called with keyword arguments. pylint calls it keyword-arg-before-vararg.

Code
W1113
Severity
warning
Message
Keyword argument before variable positional arguments list in the definition of {} function

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

… will be included in … since a positional-only parameter with this name already exists. W1117

Emitted when a function is called with a keyword argument that has the same name as a positional-only parameter and the function contains a keyword variadic parameter dict. pylint calls it kwarg-superseded-by-positional-arg.

Code
W1117
Severity
warning
Message
{} will be included in {} since a positional-only parameter with this name already exists

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

Use … formatting in logging functions. W1201

Used when a logging statement has a call form of "logging.<logging method>(format_string % (format_args...))". Use another type of string formatting instead. You can use % formatting but leave interpolation to the logging function by passing the parameters as arguments. If logging-fstring-interpolation is disabled then you can use fstring formatting. If logging-format-interpolation is disabled then you can use str.format. pylint calls it logging-not-lazy.

Code
W1201
Severity
warning
Message
Use {} formatting in logging functions

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

Use … formatting in logging functions. W1202

Used when a logging statement has a call form of "logging.<logging method>(format_string.format(format_args...))". Use another type of string formatting instead. You can use % formatting but leave interpolation to the logging function by passing the parameters as arguments. If logging-fstring-interpolation is disabled then you can use fstring formatting. If logging-not-lazy is disabled then you can use % formatting as normal. pylint calls it logging-format-interpolation.

Code
W1202
Severity
warning
Message
Use {} formatting in logging functions

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

Use … formatting in logging functions. W1203

Used when a logging statement has a call form of "logging.<logging method>(f"...")".Use another type of string formatting instead. You can use % formatting but leave interpolation to the logging function by passing the parameters as arguments. If logging-format-interpolation is disabled then you can use str.format. If logging-not-lazy is disabled then you can use % formatting as normal. pylint calls it logging-fstring-interpolation.

Code
W1203
Severity
warning
Message
Use {} formatting in logging functions

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

Using formatting for a string that does not have any interpolated variables. W1310

Used when we detect a string that does not have any interpolation variables, in which case it can be either a normal string without formatting or a bug in the code. pylint calls it format-string-without-interpolation.

Code
W1310
Severity
warning
Message
Using formatting for a string that does not have any interpolated variables

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

Using datetime.time in a boolean context. W1502

Using datetime.time in a boolean context can hide subtle bugs when the time they represent matches midnight UTC. This behaviour was fixed in Python 3.5. See https://bugs.python.org/issue13936 for reference. This message can't be emitted when using Python >= 3.5. pylint calls it boolean-datetime.

Code
W1502
Severity
warning
Message
Using datetime.time in a boolean context.

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

Redundant use of … with constant value …. W1503

The first argument of assertTrue and assertFalse is a condition. If a constant is passed as parameter, that condition will be always true. In this case a warning should be emitted. The same applies to assertEqual and assertNotEqual when both compared values are constants. pylint calls it redundant-unittest-assert.

Code
W1503
Severity
warning
Message
Redundant use of {} with constant value {}

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

Using preexec_fn keyword which may be unsafe in the presence of threads. W1509

The preexec_fn parameter is not safe to use in the presence of threads in your application. The child process could deadlock before exec is called. If you must use it, keep it trivial! Minimize the number of libraries you call into. See https://docs.python.org/3/library/subprocess.html#popen-constructor. pylint calls it subprocess-popen-preexec-fn.

Code
W1509
Severity
warning
Message
Using preexec_fn keyword which may be unsafe in the presence of threads

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

'subprocess.run' used without explicitly defining the value for 'check'. W1510

The check keyword is set to False by default. It means the process launched by subprocess.run can exit with a non-zero exit code and fail silently. It's better to set it explicitly to make clear what the error-handling behavior is. pylint calls it subprocess-run-check.

Code
W1510
Severity
warning
Message
'subprocess.run' used without explicitly defining the value for 'check'.

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

Using open without explicitly specifying an encoding. W1514

It is better to specify an encoding when opening documents. Using the system default implicitly can create problems on other operating systems. See https://peps.python.org/pep-0597/ This message can't be emitted when using Python >= 3.15. pylint calls it unspecified-encoding.

Code
W1514
Severity
warning
Message
Using open without explicitly specifying an encoding

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

'lru_cache(maxsize=None)' or 'cache' will keep all method args alive indefinitely, including 'self'. W1518

By decorating a method with lru_cache or cache the 'self' argument will be linked to the function and therefore never garbage collected. Unless your instance will never need to be garbage collected (singleton) it is recommended to refactor code to avoid this pattern or add a maxsize to the cache. The default value for maxsize is 128. pylint calls it method-cache-max-size-none.

Code
W1518
Severity
warning
Message
'lru_cache(maxsize=None)' or 'cache' will keep all method args alive indefinitely, including 'self'

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

Generic type syntax (PEP 695) is not supported by all versions included in the py-version setting. W2604

Used when the py-version set by the user is lower than 3.12 and pylint encounters generic type syntax. pylint calls it using-generic-type-syntax-in-unsupported-version.

Code
W2604
Severity
warning
Message
Generic type syntax (PEP 695) is not supported by all versions included in the py-version setting

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

Assignment expression is not supported by all versions included in the py-version setting. W2605

Used when the py-version set by the user is lower than 3.8 and pylint encounters an assignment expression (walrus) operator. pylint calls it using-assignment-expression-in-unsupported-version.

Code
W2605
Severity
warning
Message
Assignment expression is not supported by all versions included in the py-version setting

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

Positional-only arguments are not supported by all versions included in the py-version setting. W2606

Used when the py-version set by the user is lower than 3.8 and pylint encounters positional-only arguments. pylint calls it using-positional-only-args-in-unsupported-version.

Code
W2606
Severity
warning
Message
Positional-only arguments are not supported by all versions included in the py-version setting

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

Unpacking in comprehensions is not supported by all versions included in the py-version setting. W2607

Used when the py-version set by the user is lower than 3.15 and pylint encounters the * or ** unpacking added by PEP 798 in a comprehension. pylint calls it using-comprehension-unpacking-in-unsupported-version.

Code
W2607
Severity
warning
Message
Unpacking in comprehensions is not supported by all versions included in the py-version setting

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

Missing timeout argument for method '…' can cause your program to hang indefinitely. W3101

Used when a method needs a 'timeout' parameter in order to avoid waiting for a long time. If no timeout is specified explicitly the default value is used. For example for 'requests' the program will never time out (i.e. hang indefinitely). pylint calls it missing-timeout.

Code
W3101
Severity
warning
Message
Missing timeout argument for method '{}' can cause your program to hang indefinitely

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