Giter Club home page Giter Club logo

flake8-builtins's People

Contributors

asfaltboy avatar borisuvarov avatar cclauss avatar cielavenir avatar dependabot[bot] avatar dirk-thomas avatar dirn avatar dopplershift avatar felixvd avatar gammagames avatar gforcada avatar gsingh93 avatar karamanolev avatar kianmeng avatar lovetoburnswhen avatar memery-rbx avatar michael-k avatar sobolevn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flake8-builtins's Issues

Bug with format and for-loop

I have spotted that this example gives me false negative.
No errors is created, but there should be one.

def validate_date(date: str) -> datetime:
    """
    Validates that value is a valid date.

    >>> validate_date('20.12.2010')
    datetime.datetime(2010, 12, 20, 0, 0, tzinfo=<UTC>)

    """
    valid_formats = [
        '%d.%m.%y',
        '%d.%m.%Y',
        '%e.%m.%y',
        '%e.%m.%Y',
    ]

    for format in valid_formats:  # format is built-in name, but no error
        try:
            return datetime.strptime(date, format)  # no error here either
        except ValueError:
            continue

format is a built-in name that is not checked for some reason.

False negative in some control flows

Given this code sample:

try:
     1 / 0
except ZeroDivisionError as sum:
    print(sum)

This should rise an error. But it does not.
That's a bug, I guess.

I will create a PR with the test after #15 will be merged.

Add flake-job to CI

To test the code against the latest released version of flake-builtins and demonstrate its usage.

SetComp, GeneratorExpr, and DictComp are not supported

This line only checks ast.ListComp:

elif isinstance(statement, ast.ListComp):

Code: [list for list in '']

Outout:

» flake8 ex.py

ex.py

  1:1      A001  "list" is a python builtin and is being shadowed, consider renaming the variable
  [list for list in '']
  ^

We need to add support for other types of comprehensions.

Because, these types do not raise:

  • {list for list in ''}
  • (list for list in '')
  • {list: 1 for list in ''}

Warn when shadowing built-ins via `from X import Y`

The lines below overwrite built-ins and can introduce surprising bugs, but they are not flagged:

from numpy import all, any, sum
from numpy import allclose as close

Can we get a new rule that catches this?

Is it possible to disable checks for a specific builtin?

We are working a lot with histograms, which means we are talking/coding a lot about "bins".
And in the code they are named as such and i think it is best for readability of we do keep that name.

However i would still like to check all other cases of shadowing builtins. Is it possible to disable the checks just for this one builtin without disabeling A001 completely?

Edit: Does exist via --builtins-ignorelist

Support detection of shadowed built-in python modules

Similar to how check_import() compares to names of builtins but this time covering packages like logging or secrets which is a common python gotcha.

The list of these packages exists as the sys.stdlib_module_names tuple from 3.10, so I hope 🙏 we could trivially support this rule in python 3.10+ to begin with.

Some example references:

TypeError: cannot concatenate 'str' and 'int' objects

With flake8-builtins 1.3.0 and flake8 3.5.0, I'm getting the following error on Python 2.7:

Traceback (most recent call last):
  File "/home/ubuntu/virtualenvs/venv-system/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/application.py", line 396, in run
    self._run(argv)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/application.py", line 385, in _run
    self.report()
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/application.py", line 376, in report
    self.report_errors()
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/application.py", line 340, in report_errors
    results = self.file_checker_manager.report()
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/checker.py", line 267, in report
    results_reported += self._handle_results(filename, results)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/checker.py", line 166, in _handle_results
    physical_line=physical_line,
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/style_guide.py", line 384, in handle_error
    error = Violation(code, filename, line_number, column_number + 1,
TypeError: cannot concatenate 'str' and 'int' objects

This seems to be while reporting the error? This seems new in 1.3.0, no error in 1.2.1.

Split A002 to distinguish between parameter usage and definition?

I've just added this to my project, and it has caught a number of my mistakes... but it's also catching places where outside libraries chose kwargs that shadow builtins, which doesn't worry me as much: I would probably ignore these. Both cases raise A002: Would it make sense to split this into two categories?

I can try to make a PR, but I wanted to make sure this is a reasonable direction, first.

A003 should be disabled by default

Consider the following example:

class User(Model):
    id: str

    def __str__(self):
        return f"User(id:{self.id})"
        
user = User(id='123')
print(user.id)

Class attributes are almost never accessed by themselves without going through an object or a class, so what's the point of this rule? If you must preserve this rule, please disable it by default.

Does not recognize additional --builtins

As per the docs, it is possible to add builtins to flake8 by passing the --builtins flag or through config files.

However, these are not recognized by flake8-builtins:

import gettext

gettext.install("minimal_repro")


def id(s):
    return s


def _(s):
    return s


print(id("foo"))
print(_("bar"))
$ python ./no_custom_builtins.py
foo
bar
$ flake8 ./no_custom_builtins.py --builtins=_
./no_custom_builtins.py:1:1: D100 Missing docstring in public module
./no_custom_builtins.py:6:1: A001 variable "id" is shadowing a python builtin
./no_custom_builtins.py:6:1: D103 Missing docstring in public function

A001 should be reported for both functions.

Issues with detecting shadowed builtins in many places

I just upgraded to v1.2, and I feel like it's generating way too many false-positives.

First of all: I haven't thought about the full list of cases detected in the changelog yet, but in general, every of those cases should get a dedicated error code, so it's easy to silence a given kind of warning via flake8 if it's a hindrance for some projects.

What is the problem in my case specifically is class methods: For example, if I want to extend Python's logging module, I'll need to subclass things from there and override methods called filter or format.

I'd even go further and argue class methods shouldn't be checked at all by default - it's way too likely to bring up issues which can't be fixed, and the name is only shadowed in the class body, where's typically not any code other than function/variable definitions at all.

Add option to ignore certain builtins

flake8-builtins complains about variables named license, which honestly I don't understand why it even exists outside of the REPL. I don't want to rename them to lic, licence, licence_ or similar, so it would be nice to not have to sprinkle my code with # noqa everywhere.

noqa does not ignore the error

In version 1.4.1:
def id(self): # noqa: D102, A003
raises a flake8 violation although it is explicitly ignored.
A003 "id" is a python builtin, consider renaming the class attribute

A way to disable errors for class attributes

I find this plugin very useful, especially for module-level globals, function arguments, variables, etc., but class attributes are really getting in the way. Can you add a configuration option to disable the errors just for that? There are a bunch of legitimate cases where we have class attributes names that are builtins:

  • Django manage.py commands have a standard help attribute to provide command line help.
  • django-rest-framework serializers need to serializer the id attribute of a Django model, so naturally the attribute is called id.
  • Django models can have id/help/etc. fields that then go into the DB. Access to them is always scoped within the model and while id is a builtin, there is no such builtin as .id.

Python 3.10 support

Hi,

i'm trying to use builtins on VSCode without success. Using Python 3.10. Is this version not supported yet?

Thanks!

Failing build

The badge in the readme / on PyPI says that the build is failing

`AttributeError` seen with versions 1.2.0 and 1.2.1

With version flake8-builtins 1.2.0 and later I'm seeing the following issue while running flake8. It works fine with flake8-builtins 1.1.1.

Using python 2.7.14

[root@532b769a6003 /]# flake8 src/
Traceback (most recent call last):
  File "/opt/stackstorm/virtualenvs/stackstorm/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/main/application.py", line 328, in run
    self._run(argv)
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/main/application.py", line 316, in _run
    self.run_checks()
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/main/application.py", line 246, in run_checks
    self.file_checker_manager.run()
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/checker.py", line 317, in run
    self.run_parallel()
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/checker.py", line 286, in run_parallel
    for ret in pool_map:
  File "/opt/python/lib/python2.7/multiprocessing/pool.py", line 289, in <genexpr>
    return (item for chunk in result for item in chunk)
  File "/opt/python/lib/python2.7/multiprocessing/pool.py", line 673, in next
    raise value
AttributeError: 'Attribute' object has no attribute 'id'

Remove '_' from the builtins list

After upgrading to the latest version, I have faced this issue:

/Users/.../user_details_step.py:3:1: A001 "_" is a python builtin and is being shadowed, 
consider renaming the variable

But _ is a common name for unused variables, I think it is not right to annotate them with # noqa.

Split A002 to differentiate between arguments and class-level variables

E.g. with the latest version (1.2.1) I have a few examples of things like this:

class MyClass(object):
    def filter(self, a, b):
        pass

This now fails with a message:

A002 "filter" is used as an argument and thus shadows a python builtin, consider renaming the argument

This text doesn't really make sense (filter isn't an argument).

AttributeError when __enter__ method returns tuple

After upgrading to 1.2.2 we are getting this error:

Traceback (most recent call last):
  File "/usr/lib/python3.6/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/ve/lib/python3.6/site-packages/flake8/checker.py", line 648, in _run_checks
    return checker.run_checks()
  File "/ve/lib/python3.6/site-packages/flake8/checker.py", line 579, in run_checks
    self.run_ast_checks()
  File "/ve/lib/python3.6/site-packages/flake8/checker.py", line 493, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "/ve/lib/python3.6/site-packages/flake8_builtins.py", line 103, in run
    for line, offset, msg, rtype in value:
  File "/ve/lib/python3.6/site-packages/flake8_builtins.py", line 192, in check_with
    if var and var.id in BUILTINS:
AttributeError: 'Tuple' object has no attribute 'id'

This is caused by something like:

with my_manager() as (a, b):
  ....

A005 does not fire for packages

Not sure if this intended, but A005 does not fire for packages (folders) shadowing stdlib modules. So, socket/__init__.py will not lead to an flake8 error

Tuple unpacking breaks this plugin

Code

Valid python code break this linter with an exception.

>>> a, *(b, c) = 1, 2, 3
>>> print(a, b, c)
1 2 3

Problem

Reproduction:

# test.py
a, *(b, c) = 1, 2, 3

Run: flake8 test.py
Output:

» flake8 test.py
Traceback (most recent call last):
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/bin/flake8", line 10, in <module>
    sys.exit(main())
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8/main/cli.py", line 18, in main
    app.run(argv)
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8/main/application.py", line 393, in run
    self._run(argv)
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8/main/application.py", line 381, in _run
    self.run_checks()
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8/main/application.py", line 300, in run_checks
    self.file_checker_manager.run()
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8/checker.py", line 331, in run
    self.run_serial()
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8/checker.py", line 315, in run_serial
    checker.run_checks()
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8/checker.py", line 598, in run_checks
    self.run_ast_checks()
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8/checker.py", line 502, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8_builtins.py", line 106, in run
    for line, offset, msg, rtype in value:
  File "/Users/sobolev/Documents/github/wemake-python-styleguide/.venv/lib/python3.7/site-packages/flake8_builtins.py", line 124, in check_assignment
    item.value.id in BUILTINS:
AttributeError: 'Tuple' object has no attribute 'id'

Versions:

  • python3.7
  • flake8: 3.7.8
  • flake8-builtins: 1.4.1

Add option to ignore class methods and properties.

Hi, thank you for the awesome plugin!

It's helpful for me to identify if I shadow built-in function in the global or local scope.

But class methods and class attributes are somewhat different from that. Class methods do not hide anything from the global or local scope since we should refer to self before.

There are even situations where we are forced to write code like that. For example, Django management commands require a help class attribute. Django REST Framework requires list method on APIViews and ViewSets.

I don't want to lose the ability to find the redefinition of int in these files. I don't want to white noqa on each line with class attributes neither.

It would be helpful to be able to turn off that particular behavior.

What do you think?

Have a good day! 🎉

Best regards,
Artem.

Broken under SublimeLinter-flake8

Commit 628e988 broke flake8-builtins when running in SublimeText under SublimeLinter and SublimeLinter-flake8. This causes flake8 linting to stop working entirely in the editor as an exception is thrown during linting.

Traceback (most recent call last):
  File "~/.virtualenvs/linting/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "~/.virtualenvs/linting/lib/python2.7/site-packages/flake8/main.py", line 36, in main
    report = flake8_style.check_files()
  File "~/.virtualenvs/linting/lib/python2.7/site-packages/flake8/engine.py", line 181, in check_files
    return self._retry_serial(self._styleguide.check_files, paths=paths)
  File "~/.virtualenvs/linting/lib/python2.7/site-packages/flake8/engine.py", line 172, in _retry_serial
    return func(*args, **kwargs)
  File "~/.virtualenvs/linting/lib/python2.7/site-packages/pycodestyle.py", line 1877, in check_files
    runner(path)
  File "~/.virtualenvs/linting/lib/python2.7/site-packages/flake8/engine.py", line 126, in input_file
    return fchecker.check_all(expected=expected, line_offset=line_offset)
  File "~/.virtualenvs/linting/lib/python2.7/site-packages/pycodestyle.py", line 1608, in check_all
    self.check_ast()
  File "~/.virtualenvs/linting/lib/python2.7/site-packages/pycodestyle.py", line 1555, in check_ast
    for lineno, offset, text, check in checker.run():
  File "~/.virtualenvs/linting/lib/python2.7/site-packages/flake8_builtins.py", line 54, in run
    tree = ast.parse(lines)
  File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 37, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
TypeError: expected a readable buffer object

I'm not sure exactly what is going wrong here, but apparently dropping the lines added in the commit fixes the issue. I don't want to just make a PR for this though, as I'm sure I'm missing some detail as to why it was added in the first place.

`AttributeError` in new for loop checking

I'm getting this error now that I updated to 1.1.0:

Traceback (most recent call last):
  File "/Users/rmay/miniconda3/envs/py36/lib/python3.6/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/Users/rmay/miniconda3/envs/py36/lib/python3.6/site-packages/flake8/checker.py", line 648, in _run_checks
    return checker.run_checks()
  File "/Users/rmay/miniconda3/envs/py36/lib/python3.6/site-packages/flake8/checker.py", line 579, in run_checks
    self.run_ast_checks()
  File "/Users/rmay/miniconda3/envs/py36/lib/python3.6/site-packages/flake8/checker.py", line 493, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "/Users/rmay/miniconda3/envs/py36/lib/python3.6/site-packages/flake8_builtins.py", line 73, in run
    for line, offset, msg, rtype in value:
  File "/Users/rmay/miniconda3/envs/py36/lib/python3.6/site-packages/flake8_builtins.py", line 129, in check_for_loop
    if name.id in BUILTINS:
AttributeError: 'Tuple' object has no attribute 'id'

I'm seeing this on Windows, Linux, and Mac on 2.7, 3.5, 3.6. This example code (which pulls a tuple out during iteration) is enough to trigger the error (and removing that line makes the error go away):

a = [('a', 'b'), ('c', 'd')]
for i, (x, y) in enumerate(a):
    print(i, x, y)

False positive with `TypedDict`

When using with a TypeDict like:

class PaginationDict(TypedDict):
     prev: Optional[str]
     next: Optional[str]
     count: int
     data: any

This will incorrectly flag: A003 class attribute "next" is shadowing a Python builtin

These checks should be disabled when a class inherits from TypedDict

Concise Warnings

I think having a flag to enable shorter warning messages would be nice. I am using vscode and the warnings are extremely long:

image
image

Something like variable "max" is shadowing a python builtin would be plenty to convey the same meaning and cut down the length of the warning by almost half and changing the argument message to argument "object" is shadowing a python builtin would make it 50 characters shorter

posonly arguments support

This code does not raise any violations:

def some(list, /, arg): 
    ...

Because / posonly args are not checked.
It is a thing since 3.8

I will send a PR after #52 is merged

Builtins as class attrs

class StudentListSerializer(serializers.ModelSerializer):
    id = serializers.IntegerField()
    username = serializers.CharField()
    email = serializers.CharField()
    first_name = serializers.CharField()
    last_name = serializers.CharField()
    date_joined = serializers.CharField()
    avatar = S3DirectUploadURLField()

The plugin will alarm

apps/users/api/student/serializers.py:19:5: A003 "id" is a python builtin, consider renaming the class attribute

is there a configuration option to prevent checking for built-ins for class attrs?

Thanks,
Dmitry

Warn when f-string with non-local variable used? Warn when f-string converting function to str is used?

Hello,

this is the third time I am submitting this bug, hopefully this is the right place, @jack-mcivor directed me here from PyCQA/pyflakes#787 , before I submitted it to flake8 repo...

I am not sure if this belongs to this plugin and I'm not sure how to bite this exactly, but I have feeling somewhere in the back of my head, that this should be made visible to the end-user, aka programmer.

If this does not belong to this plugin, please help me and show me the direction I should take it to.

I recently made a somewhat funny bug in my codebase.

It looked like this:

SOME_CONST = f"http://some.host/{id}"

The bug-introducing character was that little "f" before the starting quote.

I meant to declare a string, that gets .format'ted some time later (like first I defined the URL with the place for the parameters, then I wanted to do SOME_CONST.format({"id": "some_id"}))

Instead, I declared a constant that looked like http://some.host/<builtin function id>. To add to the injury, .format() on that constant worked without problems at all, obviously.

First I wonder what would I like to do with that. We already have a warning for when there are f-string format characters and the string is missing the starting "f".

This would be the opposite, but only for some symbols.

On the other hand, there is very little chance somebody would want to have a string-description of a function embedded in a string constant.

So, warning about a variable found in f-string not declared in the local scope could be okay, but I am not sure if this is even possible. That SOME_CONST was declared at the top level of the module, all the imported things and symbols were available. Of course that id() was in the builtins, not in the module scope.

Maybe it would be sensible to warn the user about converting function-type object to a string in a string constant. I think that this is not the thing people like to do on the daily basis.

I would like to know your opinion on this problem first.

Any opinions?

Spurious warnings generated in flake8-bugbear

Once I upgrade to flake8-builtins 1.4.0, I started seeing these errors:

metpy/calc/thermo.py:2024:28: B007 Loop control variable 'ret' not used within the loop body. If this is intended, start the name with an underscore.

These are actually generated by the flake8-bugbear (18.2.0) plugin, and are spurious. Installing flake8-builtins 1.3.1 causes them to go away, so I'm guessing the problem actually lies in flake8-builtins.

Traceback from flake8-bugbear

Similar to #35 I see some weird interaction with flake8-bugbear since upgrading flake8-builtins to 1.4.0. Here's what I get:

multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/opt/python/3.6.3/lib/python3.6/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/opt/python/3.6.3/lib/python3.6/multiprocessing/pool.py", line 44, in mapstar
    return list(map(*args))
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/checker.py", line 648, in _run_checks
    return checker.run_checks()
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/checker.py", line 579, in run_checks
    self.run_ast_checks()
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/checker.py", line 493, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/bugbear.py", line 37, in run
    visitor.visit(self.tree)
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/bugbear.py", line 143, in visit
    super().visit(node)
  File "/opt/python/3.6.3/lib/python3.6/ast.py", line 253, in visit
    return visitor(node)
  File "/opt/python/3.6.3/lib/python3.6/ast.py", line 261, in generic_visit
    self.visit(item)
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/bugbear.py", line 143, in visit
    super().visit(node)
  File "/opt/python/3.6.3/lib/python3.6/ast.py", line 253, in visit
    return visitor(node)
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/bugbear.py", line 235, in visit_ClassDef
    self.check_for_b903(node)
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/bugbear.py", line 414, in check_for_b903
    if len(targets) > 1 or not isinstance(targets[0], ast.Attribute):
IndexError: list index out of range
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/opt/python/3.6.3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/opt/python/3.6.3/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/__main__.py", line 4, in <module>
    cli.main()
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/main/application.py", line 396, in run
    self._run(argv)
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/main/application.py", line 384, in _run
    self.run_checks()
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/main/application.py", line 310, in run_checks
    self.file_checker_manager.run()
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8_per_file_ignores.py", line 33, in run
    orig_run(self)
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/checker.py", line 319, in run
    self.run_parallel()
  File "/home/travis/build/qutebrowser/qutebrowser/.tox/flake8/lib/python3.6/site-packages/flake8/checker.py", line 288, in run_parallel
    for ret in pool_map:
  File "/opt/python/3.6.3/lib/python3.6/multiprocessing/pool.py", line 347, in <genexpr>
    return (item for chunk in result for item in chunk)
  File "/opt/python/3.6.3/lib/python3.6/multiprocessing/pool.py", line 735, in next
    raise value
IndexError: list index out of range

Can we have separate rules for exception builtins?

The source code

from requests.exceptions import ConnectionError

Raises A004 import statement "ConnectionError" is shadowing a Python builtin.

I understand that ConnectionError is a builtin, which is a subclass of OSError. However, ConnectionError is quite widely used term.

The more issue is, when we apply flake8-builtins in CI, we cannot make a new connection module which provides ConnectionError.

Can we have separate rules for such exception builtins?

/cc @felixvd @hemangandhi @ntohge

test_exception_py2 trigger an exception with python 3.9.2

While packaging the software for Debian I found that one of the test triggers a real exception. Environment is Debian Sid with python version is 3.9.2.

test_with_statement_unpack_on_list (run_tests.TestBuiltins) ... ok
test_with_statement_unpack_star (run_tests.TestBuiltins) ... ok

======================================================================
ERROR: test_exception_py2 (run_tests.TestBuiltins)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jrivero/code/debian/flake8-builtins/run_tests.py", line 329, in test_exception_py2
    tree = ast.parse(
  File "/usr/lib/python3.9/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 3
    except Exception, int:
                    ^
SyntaxError: invalid syntax

----------------------------------------------------------------------
Ran 60 tests in 0.018s

FAILED (errors=1)

Please note that I'm running the test suite with the following patch (since hypothesmith is not in Debian). I'm not sure that the error is related:

diff --git a/run_tests.py b/run_tests.py
index 3ee8091..a0594e6 100644
--- a/run_tests.py
+++ b/run_tests.py
@@ -16,7 +16,6 @@ except ImportError:
 if sys.version_info >= (3, 6):
     from hypothesis import given
     from hypothesis import reject
-    import hypothesmith
 
 
 class TestBuiltins(unittest.TestCase):
@@ -570,7 +569,6 @@ class TestBuiltins(unittest.TestCase):
 
 
 if sys.version_info >= (3, 6):
-    @given(source_code=hypothesmith.from_grammar())
     def test_builtin_works_on_many_examples(source_code):
         try:
             source = source_code.encode('utf-8-sig')

Thanks.

Feature request: Skip class attributes

Nice idea, I wish I could use it on my current project however there are a lot of class attributes (methods and variables) that are deemed acceptable to use builtin names.

Incorrectly marking conflict in methods.

# test_set.py
class MyClass:
    def set(self, value):
        pass


instance = MyClass()
instance.set("does not colide with builtins")
$ flake8 test_set.py
test_set.py:2:5: A003 "set" is a python builtin, consider renaming the class attribute

Uninstalling breaks flake8

> pip3 uninstall flake8-builtins
> flake8
ERROR:flake8.plugins.manager:No module named 'flake8_builtins'
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 158, in load_plugin
    self._load()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 135, in _load
    self._plugin = self.entry_point.load()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/entrypoints.py", line 82, in load
    mod = import_module(self.module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'flake8_builtins'
CRITICAL:flake8.plugins.manager:Flake8 failed to load plugin "A00" due to No module named 'flake8_builtins'.
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 158, in load_plugin
    self._load()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 135, in _load
    self._plugin = self.entry_point.load()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/entrypoints.py", line 82, in load
    mod = import_module(self.module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'flake8_builtins'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/.local/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/main/cli.py", line 18, in main
    app.run(argv)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/main/application.py", line 393, in run
    self._run(argv)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/main/application.py", line 380, in _run
    self.initialize(argv)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/main/application.py", line 363, in initialize
    self.find_plugins()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/main/application.py", line 199, in find_plugins
    self.check_plugins.load_plugins()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 410, in load_plugins
    plugins = list(self.manager.map(load_plugin))
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 297, in map
    yield func(self.plugins[name], *args, **kwargs)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 408, in load_plugin
    return plugin.load_plugin()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 165, in load_plugin
    raise failed_to_load
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "A00" due to No module named 'flake8_builtins'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.