flake8-2020
raw JSON → 1.8.1 verified Fri May 01 auth: no python
A flake8 plugin that checks for misuse of `sys.version` or `sys.version_info` to detect code that will break on Python 4. Current version: 1.8.1 (requires Python >=3.8). Released irregularly; last release Dec 2024.
pip install flake8-2020 Common errors
error No module named 'flake8_2020' ↓
cause Trying to import the plugin directly in Python code instead of using flake8.
fix
Do not import flake8_2020 in your code. The plugin is automatically discovered by flake8. Run 'flake8 yourfile.py'.
error flake8 says 'undefined name YTT103' when running ↓
cause The user manually defined YTT103 as a variable or function, conflicting with flake8-2020's warning codes.
fix
Do not define any variable or function named YTT*, as those are reserved for plugin error codes.
error flake8 does not detect sys.version_info issues ↓
cause The file is not being linted by flake8, or the plugin is not installed correctly.
fix
Ensure flake8-2020 is installed in the same environment as flake8. Run 'pip show flake8-2020' to verify.
Warnings
gotcha The plugin is automatically enabled when installed; no configuration needed. However, it only works if flake8 is run on the file. ↓
fix Run flake8 from the command line or integrate into your pre-commit hooks.
deprecated The deprecated YTT301 (sys.version[0:3] used) and YTT302 (sys.version[2] used) are still emitted but may be removed in future versions. ↓
fix Use sys.version_info.major instead of string slicing.
breaking In version 1.8.0, the minimum Python version was raised to 3.8, dropping Python 3.6 and 3.7 support. ↓
fix Upgrade to Python 3.8 or later.
Imports
- flake8-2020
Installed as a plugin; no explicit import needed
Quickstart
# Run flake8 with the plugin enabled (flake8 discovers it automatically)
# The plugin checks for Python 4 compatibility issues
import sys
print(sys.version_info[0]) # This will trigger YTT103 (sys.version_info used as tuple)
print(sys.version_info.major) # Correct usage