flake8-builtins


Nameflake8-builtins JSON
Version 2.4.0 PyPI version JSON
download
home_pageNone
SummaryCheck for python builtins being used as variables or parameters
upload_time2024-04-01 10:48:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords flake8 pep8 python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. -*- coding: utf-8 -*-

.. image:: https://github.com/gforcada/flake8-builtins/actions/workflows/testing.yml/badge.svg?branch=main
   :target: https://github.com/gforcada/flake8-builtins/actions/workflows/testing.yml

.. image:: https://coveralls.io/repos/gforcada/flake8-builtins/badge.svg?branch=main
   :target: https://coveralls.io/github/gforcada/flake8-builtins?branch=main

Flake8 Builtins plugin
======================
Check for python builtins being used as variables or parameters.

Imagine some code like this:

.. code:: Python

    def max_values(list, list2):
        max = list[0]
        for x in list:
            if x > 0:
                max = x

        all_values = list()
        all_values.append(max)

        max = list2[0]
        for x in list2:
            if x > 0:
                max = x
        all_values.append(max)

        return all_values

    max_values([3, 4, 5, ], [5, 6, 7])

The last statement is not returning ``[5, 7]`` as one would expect,
instead is raising this exception::

    Traceback (most recent call last):
      File "test.py", line 17, in <module>
        max_values([3,4,5], [4,5,6])
      File "bla.py", line 6, in max_values
        all_values = list()
    TypeError: 'list' object is not callable

**Why?** Because ``max_value`` function's first argument is ``list`` a Python builtin.
Python allows to override them, but although could be useful in some really specific use cases,
the general approach is to **not** do that as code then can suddenly break without a clear trace.

Example
-------
Given the following code:

.. code:: Python

    def my_method(object, list, dict):
        max = 5
        min = 3
        zip = (4, 3)

The following warnings are shown (via flake8)::

   test.py:1:15: A002 argument "object" is shadowing a python builtin
   test.py:1:23: A002 argument "list" is shadowing a python builtin
   test.py:1:29: A002 argument "dict" is shadowing a python builtin
   test.py:2:5: A001 variable "max" is shadowing a python builtin
   test.py:3:5: A001 variable "min" is shadowing a python builtin
   test.py:4:5: A001 variable "zip" is shadowing a python builtin

Install
-------
Install with pip::

    $ python -m pip install flake8-builtins

Options
-------

One can use `--builtins-ignorelist` option, or configuration option,
to ignore a custom list of builtins::

    $ flake8 --builtins-ignorelist id,copyright *.py

Requirements
------------
- Python 3.8, 3.9, 3.10, 3.11, 3.12, and pypy3
- flake8

Rules
-----

A001:
  A variable is shadowing a Python builtin.

A002:
  An argument is shadowing a Python builtin.

A003:
  A class attribute is shadowing a Python builtin.

A004:
  An import statement is shadowing a Python builtin.

A005:
  A module is shadowing a Python builtin module (e.g: `logging` or `socket`)

A006:
  A lambda argument is shadowing a Python builtin.

License
-------
GPL 2.0

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flake8-builtins",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "flake8, pep8, python",
    "author": null,
    "author_email": "Gil Forcada Codinachs <gil.gnome@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d8/67/445b708368a93ac62a91113a5528406d912133f2db51a77f379cb7bb72fe/flake8_builtins-2.4.0.tar.gz",
    "platform": null,
    "description": ".. -*- coding: utf-8 -*-\n\n.. image:: https://github.com/gforcada/flake8-builtins/actions/workflows/testing.yml/badge.svg?branch=main\n   :target: https://github.com/gforcada/flake8-builtins/actions/workflows/testing.yml\n\n.. image:: https://coveralls.io/repos/gforcada/flake8-builtins/badge.svg?branch=main\n   :target: https://coveralls.io/github/gforcada/flake8-builtins?branch=main\n\nFlake8 Builtins plugin\n======================\nCheck for python builtins being used as variables or parameters.\n\nImagine some code like this:\n\n.. code:: Python\n\n    def max_values(list, list2):\n        max = list[0]\n        for x in list:\n            if x > 0:\n                max = x\n\n        all_values = list()\n        all_values.append(max)\n\n        max = list2[0]\n        for x in list2:\n            if x > 0:\n                max = x\n        all_values.append(max)\n\n        return all_values\n\n    max_values([3, 4, 5, ], [5, 6, 7])\n\nThe last statement is not returning ``[5, 7]`` as one would expect,\ninstead is raising this exception::\n\n    Traceback (most recent call last):\n      File \"test.py\", line 17, in <module>\n        max_values([3,4,5], [4,5,6])\n      File \"bla.py\", line 6, in max_values\n        all_values = list()\n    TypeError: 'list' object is not callable\n\n**Why?** Because ``max_value`` function's first argument is ``list`` a Python builtin.\nPython allows to override them, but although could be useful in some really specific use cases,\nthe general approach is to **not** do that as code then can suddenly break without a clear trace.\n\nExample\n-------\nGiven the following code:\n\n.. code:: Python\n\n    def my_method(object, list, dict):\n        max = 5\n        min = 3\n        zip = (4, 3)\n\nThe following warnings are shown (via flake8)::\n\n   test.py:1:15: A002 argument \"object\" is shadowing a python builtin\n   test.py:1:23: A002 argument \"list\" is shadowing a python builtin\n   test.py:1:29: A002 argument \"dict\" is shadowing a python builtin\n   test.py:2:5: A001 variable \"max\" is shadowing a python builtin\n   test.py:3:5: A001 variable \"min\" is shadowing a python builtin\n   test.py:4:5: A001 variable \"zip\" is shadowing a python builtin\n\nInstall\n-------\nInstall with pip::\n\n    $ python -m pip install flake8-builtins\n\nOptions\n-------\n\nOne can use `--builtins-ignorelist` option, or configuration option,\nto ignore a custom list of builtins::\n\n    $ flake8 --builtins-ignorelist id,copyright *.py\n\nRequirements\n------------\n- Python 3.8, 3.9, 3.10, 3.11, 3.12, and pypy3\n- flake8\n\nRules\n-----\n\nA001:\n  A variable is shadowing a Python builtin.\n\nA002:\n  An argument is shadowing a Python builtin.\n\nA003:\n  A class attribute is shadowing a Python builtin.\n\nA004:\n  An import statement is shadowing a Python builtin.\n\nA005:\n  A module is shadowing a Python builtin module (e.g: `logging` or `socket`)\n\nA006:\n  A lambda argument is shadowing a Python builtin.\n\nLicense\n-------\nGPL 2.0\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Check for python builtins being used as variables or parameters",
    "version": "2.4.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/gforcada/flake8-builtins/issues",
        "Changelog": "https://github.com/gforcada/flake8-builtins/blob/main/CHANGES.rst",
        "Homepage": "https://github.com/gforcada/flake8-builtins"
    },
    "split_keywords": [
        "flake8",
        " pep8",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a431d3bec8ad1bf32f1040ee1c28dd9141b39ab0bd0e4317a3a76f5c36f34533",
                "md5": "a279b6f8663472cd2491d37e576298ea",
                "sha256": "a9a2002855947081019a14e292200ab6e17ed637c0056aaa87ef23ea46fe8070"
            },
            "downloads": -1,
            "filename": "flake8_builtins-2.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a279b6f8663472cd2491d37e576298ea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11944,
            "upload_time": "2024-04-01T10:48:16",
            "upload_time_iso_8601": "2024-04-01T10:48:16.679985Z",
            "url": "https://files.pythonhosted.org/packages/a4/31/d3bec8ad1bf32f1040ee1c28dd9141b39ab0bd0e4317a3a76f5c36f34533/flake8_builtins-2.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d867445b708368a93ac62a91113a5528406d912133f2db51a77f379cb7bb72fe",
                "md5": "8c4339284e1198410bbbfe4ac650c97b",
                "sha256": "03ddfdbb40c6a0ad5375668b89d9d919970d026d65e6bb53185081c99822e466"
            },
            "downloads": -1,
            "filename": "flake8_builtins-2.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8c4339284e1198410bbbfe4ac650c97b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16431,
            "upload_time": "2024-04-01T10:48:18",
            "upload_time_iso_8601": "2024-04-01T10:48:18.828364Z",
            "url": "https://files.pythonhosted.org/packages/d8/67/445b708368a93ac62a91113a5528406d912133f2db51a77f379cb7bb72fe/flake8_builtins-2.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-01 10:48:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gforcada",
    "github_project": "flake8-builtins",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flake8-builtins"
}
        
Elapsed time: 4.45687s