Programming Search⌘K

Python lints, page 8 of 8

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

Suspicious …-part chained comparison using semantically incompatible operators (…). W3601

Used when there is a chained comparison where one expression is part of two comparisons that belong to different semantic groups ("<" does not mean the same thing as "is", chaining them in "0 < x is None" is probably a mistake). pylint calls it bad-chained-comparison.

Code
W3601
Severity
warning
Message
Suspicious {}-part chained comparison using semantically incompatible operators ({})

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

Iterated list '…' is being modified inside for loop body, consider iterating through a copy of it instead. W4701

Emitted when items are added or removed to a list being iterated through. Doing so can result in unexpected behaviour, that is why it is preferred to use a copy of the list. pylint calls it modified-iterating-list.

Code
W4701
Severity
warning
Message
Iterated list '{}' is being modified inside for loop body, consider iterating through a copy of it instead.

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

Iterator '…' from an outer scope is reused or consumed in a nested loop. W4801

Used when an iterator defined in an outer loop scope is consumed in a nested loop. Because iterators are stateful and exhausted upon consumption, the inner loop will fully consume the iterator during the first iteration of the outer loop, leaving it empty for all subsequent iterations. pylint calls it looping-through-iterator.

Code
W4801
Severity
warning
Message
Iterator '{}' from an outer scope is reused or consumed in a nested loop.

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

Checks for uses of sys.version:3. YTT101

If the current major or minor version consists of multiple digits, sys.version:3 will truncate the version number (e.g., "3.10" would become "3.1"). This is likely unintended, and can lead to subtle bugs if the version string is used to test against a specific Python version. Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT101
Message
`sys.version[:3]` referenced (python3.10), use `sys.version_info`

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

Checks for uses of sys.version2. YTT102

If the current major or minor version consists of multiple digits, sys.version2 will select the first digit of the minor number only (e.g., "3.10" would evaluate to "1"). This is likely unintended, and can lead to subtle bugs if the version is used to test against a minor version number. Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT102
Message
`sys.version[2]` referenced (python3.10), use `sys.version_info`

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

Checks for comparisons that test sys.version against string literals, such that the comparison will evaluate to False on Python 3.10 or later. YTT103

Comparing sys.version to a string is error-prone and may cause subtle bugs, as the comparison will be performed lexicographically, not semantically. For example, sys.version > "3.9" will evaluate to False when using Python 3.10, as "3.10" is lexicographically "less" than "3.9". Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT103
Message
`sys.version` compared to string (python3.10), use `sys.version_info`

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

Checks for equality comparisons against the major version returned by sys.version_info (e.g., sys.version_info0 == 3 or sys.version_info0 != 3). YTT201

Using sys.version_info0 == 3 to verify that the major version is Python 3 or greater will fail if the major version number is ever incremented (e.g., to Python 4). This is likely unintended, as code that uses this comparison is likely intended to be run on Python 2, but would now run on Python 4 too. Similarly, using sys.version_info0 != 3 to check for Python 2 will also fail if the major version number is incremented. Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT201
Message
`sys.version_info[0] == 3` referenced (python4), use `>=`
Message
`sys.version_info[0] != 3` referenced (python4), use `<`

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

Checks for uses of six.PY3. YTT202

six.PY3 will evaluate to False on Python 4 and greater. This is likely unintended, and may cause code intended to run on Python 2 to run on Python 4 too. Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT202
Message
`six.PY3` referenced (python4), use `not six.PY2`

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

Checks for comparisons that test sys.version_info1 against an integer. YTT203

Comparisons based on the current minor version number alone can cause subtle bugs and would likely lead to unintended effects if the Python major version number were ever incremented (e.g., to Python 4). Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT203
Message
`sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to tuple

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

Checks for comparisons that test sys.version_info.minor against an integer. YTT204

Comparisons based on the current minor version number alone can cause subtle bugs and would likely lead to unintended effects if the Python major version number were ever incremented (e.g., to Python 4). Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT204
Message
`sys.version_info.minor` compared to integer (python4), compare `sys.version_info` to tuple

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

Checks for uses of sys.version0. YTT301

If the current major or minor version consists of multiple digits, sys.version0 will select the first digit of the major version number only (e.g., "10.2" would evaluate to "1"). This is likely unintended, and can lead to subtle bugs if the version string is used to test against a major version number. Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT301
Message
`sys.version[0]` referenced (python10), use `sys.version_info`

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

Checks for comparisons that test sys.version against string literals, such that the comparison would fail if the major version number were ever incremented to Python 10 or higher. YTT302

Comparing sys.version to a string is error-prone and may cause subtle bugs, as the comparison will be performed lexicographically, not semantically. Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT302
Message
`sys.version` compared to string (python10), use `sys.version_info`

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

Checks for uses of sys.version:1. YTT303

If the major version number consists of more than one digit, this will select the first digit of the major version number only (e.g., "10.0" would evaluate to "1"). This is likely unintended, and can lead to subtle bugs in future versions of Python if the version string is used to test against a specific major version number. Ruff takes this rule from flake8-2020 and made it stable in v0.0.113.

Code
YTT303
Message
`sys.version[:1]` referenced (python10), use `sys.version_info`

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