Skip to content

bad-version-info-order (PYI066)

Derived from the flake8-pyi linter.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for if-else statements with sys.version_info comparisons that use < comparators.

Why is this bad?

As a convention, branches that correspond to newer Python versions should come first when using sys.version_info comparisons. This makes it easier to understand the desired behavior, which typically corresponds to the latest Python versions.

Example

import sys

if sys.version_info < (3, 10):
    def read_data(x, *, preserve_order=True): ...

else:
    def read_data(x): ...

Use instead:

if sys.version_info >= (3, 10):
    def read_data(x): ...

else:
    def read_data(x, *, preserve_order=True): ...