Skip to content

complex-if-statement-in-stub (PYI002)#

Derived from the flake8-pyi linter.

What it does#

Checks for if statements with complex conditionals in stubs.

Why is this bad?#

Stub files support simple conditionals to test for differences in Python versions and platforms. However, type checkers only understand a limited subset of these conditionals; complex conditionals may result in false positives or false negatives.

Example#

import sys

if (2, 7) < sys.version_info < (3, 5):
    ...

Use instead:

import sys

if sys.version_info < (3, 5):
    ...