class ImplicitBooleanessChecker(checkers.BaseChecker): (source)
Checks for incorrect usage of comparisons or len() inside conditions. Incorrect usage of len() Pep8 states: For sequences, (strings, lists, tuples), use the fact that empty sequences are false. Yes: if not seq: if seq: No: if len(seq): if not len(seq): Problems detected: * if len(sequence): * if not len(sequence): * elif len(sequence): * elif not len(sequence): * while len(sequence): * while not len(sequence): * assert len(sequence): * assert not len(sequence): * bool(len(sequence)) Incorrect usage of empty literal sequences; (), [], {}, For empty sequences, (dicts, lists, tuples), use the fact that empty sequences are false. Yes: if variable: if not variable No: if variable == empty_literal: if variable != empty_literal: Problems detected: * comparison such as variable == empty_literal: * comparison such as variable != empty_literal:
Static Method | base |
Return all names inherited by a class instance or those returned by a function. |
Static Method | instance |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
`not len(S)` must become `not S` regardless if the parent block is a test condition or something else (boolean expression) e.g. `if not len(S):`. |
Class Variable | msgs |
Undocumented |
Class Variable | name |
Name of the provider. |
Class Variable | options |
Options provided by this provider. |
Method | _check |
Check for left side and right side of the node for empty literals. |
Method | _get |
Undocumented |
Method | _implicit |
Helper to get the right message for "use-implicit-booleaness-not-comparison". |
Inherited from BaseChecker
:
Method | __eq__ |
Permit to assert Checkers are equal. |
Method | __gt__ |
Sorting of checkers. |
Method | __hash__ |
Make Checker hashable. |
Method | __init__ |
Checker instances should have the linter as argument. |
Method | __repr__ |
Undocumented |
Method | __str__ |
This might be incomplete because multiple classes inheriting BaseChecker can have the same name. |
Method | add |
Undocumented |
Method | check |
Check the consistency of msgid. |
Method | close |
Called after visiting project (i.e set of modules). |
Method | create |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | open |
Called before visiting project (i.e. set of modules). |
Method | reduce |
Undocumented |
Class Variable | enabled |
Undocumented |
Class Variable | reports |
Undocumented |
Instance Variable | linter |
Undocumented |
Property | messages |
Undocumented |
Inherited from _ArgumentsProvider
(via BaseChecker
):
Method | get |
DEPRECATED: Return the dictionary defining an option given its name. |
Method | level |
Undocumented |
Method | load |
DEPRECATED: Initialize the provider using default values. |
Method | option |
DEPRECATED: Get the config attribute corresponding to opt. |
Method | option |
DEPRECATED: Get the current value for the given option. |
Method | options |
DEPRECATED. |
Method | options |
DEPRECATED: Return an iterator on options grouped by section. |
Method | set |
DEPRECATED: Method called to set an option (registered in the options list). |
Class Variable | option |
Option groups of this provider and their descriptions. |
Property | config |
Undocumented |
Property | level |
Undocumented |
Instance Variable | _arguments |
The manager that will parse and register any options provided. |
Instance Variable | _level |
Undocumented |
def base_names_of_instance(node:
util.UninferableBase|bases.Instance
) -> list[ str]
:
(source)
¶
Return all names inherited by a class instance or those returned by a function. The inherited names include 'object'.
def visit_call(self, node:
nodes.Call
):
(source)
¶
Undocumented
def visit_compare(self, node:
nodes.Compare
):
(source)
¶
Undocumented
def visit_unaryop(self, node:
nodes.UnaryOp
):
(source)
¶
`not len(S)` must become `not S` regardless if the parent block is a test condition or something else (boolean expression) e.g. `if not len(S):`.