flake8-2020


Nameflake8-2020 JSON
Version 1.8.1 PyPI version JSON
download
home_pagehttps://github.com/asottile/flake8-2020
Summaryflake8 plugin which checks for misuse of `sys.version` or `sys.version_info`
upload_time2023-06-10 19:05:11
maintainer
docs_urlNone
authorAnthony Sottile
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![build status](https://github.com/asottile/flake8-2020/actions/workflows/main.yml/badge.svg)](https://github.com/asottile/flake8-2020/actions/workflows/main.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/asottile/flake8-2020/main.svg)](https://results.pre-commit.ci/latest/github/asottile/flake8-2020/main)

flake8-2020
===========

flake8 plugin which checks for misuse of `sys.version` or `sys.version_info`

this will become a problem when `python3.10` or `python4.0` exists (presumably
during the year 2020).

you might also find an early build of [python3.10] useful

[python3.10]: https://github.com/asottile/python3.10

## installation

```bash
pip install flake8-2020
```

## flake8 codes

| Code   | Description                                            |
|--------|--------------------------------------------------------|
| YTT101 | `sys.version[:3]` referenced (python3.10)              |
| YTT102 | `sys.version[2]` referenced (python3.10)               |
| YTT103 | `sys.version` compared to string (python3.10)          |
| YTT201 | `sys.version_info[0] == 3` referenced (python4)        |
| YTT202 | `six.PY3` referenced (python4)                         |
| YTT203 | `sys.version_info[1]` compared to integer (python4)    |
| YTT204 | `sys.version_info.minor` compared to integer (python4) |
| YTT301 | `sys.version[0]` referenced (python10)                 |
| YTT302 | `sys.version` compared to string (python10)            |
| YTT303 | `sys.version[:1]` referenced (python10)                |

## rationale

lots of code incorrectly references the `sys.version` and `sys.version_info`
members.  in particular, this will cause some issues when the version of python
after python3.9 is released.  my current recommendation is 3.10 since I believe
it breaks less code, here's a few patterns that will cause issues:

```python
# in python3.10 this will report as '3.1' (should be '3.10')
python_version = sys.version[:3]  # YTT101
# in python3.10 this will report as '1' (should be '10')
py_minor = sys.version[2]
# in python3.10 this will be False (which goes against developer intention)
sys.version >= '3.5'  # YTT103


# correct way to do this
python_version = '{}.{}'.format(*sys.version_info)
py_minor = str(sys.version_info[1])
sys.version_info >= (3, 5)
```

```python
# in python4 this will report as `False` (and suddenly run python2 code!)
is_py3 = sys.version_info[0] == 3  # YTT201

# in python4 this will report as `False` (six violates YTT201!)
if six.PY3:  # YTT202
    print('python3!')

if sys.version_info[0] >= 3 and sys.version_info[1] >= 5:  # YTT203
    print('py35+')

if sys.version_info.major >= 3 and sys.version_info.minor >= 6:  # YTT204
    print('py36+')

# correct way to do this
is_py3 = sys.version_info >= (3,)

if not six.PY2:
    print('python3!')

if sys.version_info >= (3, 5):
    print('py35+')

if sys.version_info >= (3, 6):
    print('py36+')
```

```python
# in python10 this will report as '1'
python_major_version = sys.version[0]  # YTT301
# in python10 this will be False
if sys.version >= '3':  # YTT302
    print('python3!')
# in python10 this will be False
if sys.version[:1] >= '3':  # YTT303
    print('python3!')


# correct way to do this
python_major_version = str(sys.version_info[0])

if sys.version_info >= (3,):
    print('python3!')

if sys.version_info >= (3,):
    print('python3!')
```

## as a pre-commit hook

See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions

Sample `.pre-commit-config.yaml`:

```yaml
-   repo: https://github.com/pycqa/flake8
    rev: 3.7.8
    hooks:
    -   id: flake8
        additional_dependencies: [flake8-2020==1.6.1]
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/asottile/flake8-2020",
    "name": "flake8-2020",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Anthony Sottile",
    "author_email": "asottile@umich.edu",
    "download_url": "https://files.pythonhosted.org/packages/cf/0b/e71a0d9efd854a631e2d51707676886997c73bec70c3c221b84601b976d2/flake8_2020-1.8.1.tar.gz",
    "platform": null,
    "description": "[![build status](https://github.com/asottile/flake8-2020/actions/workflows/main.yml/badge.svg)](https://github.com/asottile/flake8-2020/actions/workflows/main.yml)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/asottile/flake8-2020/main.svg)](https://results.pre-commit.ci/latest/github/asottile/flake8-2020/main)\n\nflake8-2020\n===========\n\nflake8 plugin which checks for misuse of `sys.version` or `sys.version_info`\n\nthis will become a problem when `python3.10` or `python4.0` exists (presumably\nduring the year 2020).\n\nyou might also find an early build of [python3.10] useful\n\n[python3.10]: https://github.com/asottile/python3.10\n\n## installation\n\n```bash\npip install flake8-2020\n```\n\n## flake8 codes\n\n| Code   | Description                                            |\n|--------|--------------------------------------------------------|\n| YTT101 | `sys.version[:3]` referenced (python3.10)              |\n| YTT102 | `sys.version[2]` referenced (python3.10)               |\n| YTT103 | `sys.version` compared to string (python3.10)          |\n| YTT201 | `sys.version_info[0] == 3` referenced (python4)        |\n| YTT202 | `six.PY3` referenced (python4)                         |\n| YTT203 | `sys.version_info[1]` compared to integer (python4)    |\n| YTT204 | `sys.version_info.minor` compared to integer (python4) |\n| YTT301 | `sys.version[0]` referenced (python10)                 |\n| YTT302 | `sys.version` compared to string (python10)            |\n| YTT303 | `sys.version[:1]` referenced (python10)                |\n\n## rationale\n\nlots of code incorrectly references the `sys.version` and `sys.version_info`\nmembers.  in particular, this will cause some issues when the version of python\nafter python3.9 is released.  my current recommendation is 3.10 since I believe\nit breaks less code, here's a few patterns that will cause issues:\n\n```python\n# in python3.10 this will report as '3.1' (should be '3.10')\npython_version = sys.version[:3]  # YTT101\n# in python3.10 this will report as '1' (should be '10')\npy_minor = sys.version[2]\n# in python3.10 this will be False (which goes against developer intention)\nsys.version >= '3.5'  # YTT103\n\n\n# correct way to do this\npython_version = '{}.{}'.format(*sys.version_info)\npy_minor = str(sys.version_info[1])\nsys.version_info >= (3, 5)\n```\n\n```python\n# in python4 this will report as `False` (and suddenly run python2 code!)\nis_py3 = sys.version_info[0] == 3  # YTT201\n\n# in python4 this will report as `False` (six violates YTT201!)\nif six.PY3:  # YTT202\n    print('python3!')\n\nif sys.version_info[0] >= 3 and sys.version_info[1] >= 5:  # YTT203\n    print('py35+')\n\nif sys.version_info.major >= 3 and sys.version_info.minor >= 6:  # YTT204\n    print('py36+')\n\n# correct way to do this\nis_py3 = sys.version_info >= (3,)\n\nif not six.PY2:\n    print('python3!')\n\nif sys.version_info >= (3, 5):\n    print('py35+')\n\nif sys.version_info >= (3, 6):\n    print('py36+')\n```\n\n```python\n# in python10 this will report as '1'\npython_major_version = sys.version[0]  # YTT301\n# in python10 this will be False\nif sys.version >= '3':  # YTT302\n    print('python3!')\n# in python10 this will be False\nif sys.version[:1] >= '3':  # YTT303\n    print('python3!')\n\n\n# correct way to do this\npython_major_version = str(sys.version_info[0])\n\nif sys.version_info >= (3,):\n    print('python3!')\n\nif sys.version_info >= (3,):\n    print('python3!')\n```\n\n## as a pre-commit hook\n\nSee [pre-commit](https://github.com/pre-commit/pre-commit) for instructions\n\nSample `.pre-commit-config.yaml`:\n\n```yaml\n-   repo: https://github.com/pycqa/flake8\n    rev: 3.7.8\n    hooks:\n    -   id: flake8\n        additional_dependencies: [flake8-2020==1.6.1]\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "flake8 plugin which checks for misuse of `sys.version` or `sys.version_info`",
    "version": "1.8.1",
    "project_urls": {
        "Homepage": "https://github.com/asottile/flake8-2020"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "36f014c6c25768ddc81999733e7bed89e9285b273920505180155e351ed92dc5",
                "md5": "cf642810307c7e955b30a234a3061aaa",
                "sha256": "59b6b8ac01cde10ef11b31a2c9aa15b4509d828ae115ee5be34464b9e4de4ea6"
            },
            "downloads": -1,
            "filename": "flake8_2020-1.8.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cf642810307c7e955b30a234a3061aaa",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 4885,
            "upload_time": "2023-06-10T19:05:09",
            "upload_time_iso_8601": "2023-06-10T19:05:09.965262Z",
            "url": "https://files.pythonhosted.org/packages/36/f0/14c6c25768ddc81999733e7bed89e9285b273920505180155e351ed92dc5/flake8_2020-1.8.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cf0be71a0d9efd854a631e2d51707676886997c73bec70c3c221b84601b976d2",
                "md5": "2898bfc6977ff7b71cad5fed49bd531f",
                "sha256": "094ea95e8b614c3bd123fd4f007be28ec117ca57a6169903d4baaabe78e3e590"
            },
            "downloads": -1,
            "filename": "flake8_2020-1.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2898bfc6977ff7b71cad5fed49bd531f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4527,
            "upload_time": "2023-06-10T19:05:11",
            "upload_time_iso_8601": "2023-06-10T19:05:11.430849Z",
            "url": "https://files.pythonhosted.org/packages/cf/0b/e71a0d9efd854a631e2d51707676886997c73bec70c3c221b84601b976d2/flake8_2020-1.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-10 19:05:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "asottile",
    "github_project": "flake8-2020",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flake8-2020"
}
        
Elapsed time: 0.09760s