sys-version-slice3 (YTT101)#
Derived from the flake8-2020 linter.
What it does#
Checks for uses of sys.version[:3].
Why is this bad?#
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.
Instead, use sys.version_info to access the current major and minor
version numbers as a tuple, which can be compared to other tuples
without issue.
Example#
Use instead: