Check for python builtins being used as variables or parameters

Overview
https://travis-ci.org/gforcada/flake8-builtins.svg?branch=master https://coveralls.io/repos/gforcada/flake8-builtins/badge.svg?branch=master

Flake8 Builtins plugin

Check for python builtins being used as variables or parameters.

Imagine some code like this:

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:

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:

$ pip install flake8-builtins

Requirements

  • Python 2.7, 3.6, 3.7, 3.8
  • flake8

License

GPL 2.0

Static type checker for Python

Static type checker for Python Speed Pyright is a fast type checker meant for large Python source bases. It can run in a β€œwatch” mode and performs fas

Microsoft 9.2k Jan 03, 2023
πŸ¦† Better duck-typing with mypy-compatible extensions to Protocol

πŸ¦† Quacks If it walks like a duck and it quacks like a duck, then it must be a duck Thanks to PEP544, Python now has protocols: a way to define duck t

Arie Bovenberg 9 Nov 14, 2022
An open-source, mini imitation of GitHub Copilot for Emacs.

Second Mate An open-source, mini imitation of GitHub Copilot using EleutherAI GPT-Neo-2.7B (via Huggingface Model Hub) for Emacs. This is a much small

Sam Rawal 238 Dec 27, 2022
A Pylint plugin to analyze Flask applications.

pylint-flask About pylint-flask is Pylint plugin for improving code analysis when editing code using Flask. Inspired by pylint-django. Problems pylint

Joe Schafer 62 Sep 18, 2022
Naming Convention checker for Python

PEP 8 Naming Conventions Check your code against PEP 8 naming conventions. This module provides a plugin for flake8, the Python code checker. (It repl

Python Code Quality Authority 411 Dec 23, 2022
Pyright extension for coc.nvim

coc-pyright Pyright extension for coc.nvim Install :CocInstall coc-pyright Note: Pyright may not work as expected if can't detect project root correct

Heyward Fann 1.1k Jan 02, 2023
Static Typing for Python

Python static typing home. Contains the source for typing_extensions and the documentation. Also hosts a user help forum.

Python 1.3k Jan 06, 2023
flake8 plugin to run black for checking Python coding style

flake8-black Introduction This is an MIT licensed flake8 plugin for validating Python code style with the command line code formatting tool black. It

Peter Cock 146 Dec 15, 2022
A Python Parser

parso - A Python Parser Parso is a Python parser that supports error recovery and round-trip parsing for different Python versions (in multiple Python

Dave Halter 520 Dec 26, 2022
Performant type-checking for python.

Pyre is a performant type checker for Python compliant with PEP 484. Pyre can analyze codebases with millions of lines of code incrementally – providi

Facebook 6.2k Jan 04, 2023
Flake8 plugin to find commented out or dead code

flake8-eradicate flake8 plugin to find commented out (or so called "dead") code. This is quite important for the project in a long run. Based on eradi

wemake.services 277 Dec 27, 2022
A static type analyzer for Python code

pytype - πŸ¦† βœ” Pytype checks and infers types for your Python code - without requiring type annotations. Pytype can: Lint plain Python code, flagging c

Google 4k Dec 31, 2022
Reference implementation of sentinels for the Python stdlib

Sentinels This is a reference implementation of a utility for the definition of sentinel values in Python. This also includes a draft PEP for the incl

Tal Einat 22 Aug 27, 2022
OpenStack Hacking Style Checks. Mirror of code maintained at opendev.org.

Introduction hacking is a set of flake8 plugins that test and enforce the OpenStack StyleGuide Hacking pins its dependencies, as a new release of some

Mirrors of opendev.org/openstack 224 Jan 05, 2023
Collection of awesome Python types, stubs, plugins, and tools to work with them.

Awesome Python Typing Collection of awesome Python types, stubs, plugins, and tools to work with them. Contents Static type checkers Dynamic type chec

TypedDjango 1.2k Jan 04, 2023
πŸ‘» Phantom types for Python

phantom-types Phantom types for Python will help you make illegal states unrepresentable and avoid shotgun parsing by enabling you to practice "Parse,

Anton Agestam 118 Dec 22, 2022
Backport Python 3.8+ typing utils & add issubtype & more

typing-utils Backport Python3.8+ typing utils & issubtype & more Install API issubtype get_origin get_args get_type_hints Install pip install typi

10 Nov 09, 2022
Flake8 wrapper to make it nice, legacy-friendly, configurable.

THE PROJECT IS ARCHIVED Forks: https://github.com/orsinium/forks It's a Flake8 wrapper to make it cool. Lint md, rst, ipynb, and more. Shareable and r

Life4 232 Dec 16, 2022
Mypy plugin and stubs for SQLAlchemy

Pythonista Stubs Stubs for the Pythonista iOS API. This allows for better error detection and IDE / editor autocomplete. Installation and Usage pip in

Dropbox 521 Dec 29, 2022
Rust like Option and Result types in Python

Option Rust-like Option and Result types in Python, slotted and fully typed. An Option type represents an optional value, every Option is either Some

45 Dec 13, 2022