Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Add flake8-bugbear to the test suite #9279

@ShadowJonathan

Description

@ShadowJonathan

Adding the flake8-bugbear plugin can help us catch bugs early before they occur, adding it on the codebase produces a enormous amount of the following codes;

  • B001 Do not use bare 'except:', it also catches unexpected events like memory errors, interrupts, system exit, and so on. Prefer 'except Exception:'. If you're sure what you're doing, be explicit and write 'except BaseException:'.
  • B006 Do not use mutable data structures for argument defaults. They are created during function definition time. All calls to the function reuse this one instance of that data structure, persisting changes between them.
  • B007 Loop control variable 'encoded_signature' not used within the loop body. If this is intended, start the name with an underscore.
  • B008 Do not perform function calls in argument defaults. The call is performed only once at function definition time. All calls to your function will reuse the result of that definition-time function call. If this is intended, assign the function call to a module-level variable and use that variable as a default value.
  • B010 Do not call setattr with a constant attribute value, it is not any safer than normal property access.
  • B306 'BaseException.message' has been deprecated as of Python 2.6 and is removed in Python 3. Use 'str(e)' to access the user-readable message. Use 'e.args' to access arguments passed to the exception.

I think that's reasonable to take a closer look at where bugbear notes these linting errors, as it indeed can look likely for these bugs to exist there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-TaskRefactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions