class CodeStyleChecker(BaseChecker): (source)
Checkers that can improve code consistency. As such they don't necessarily provide a performance benefit and are often times opinionated. Before adding another checker here, consider this: 1. Does the checker provide a clear benefit, i.e. detect a common issue or improve performance => it should probably be part of the core checker classes 2. Is it something that would improve code consistency, maybe because it's slightly better with regard to performance and therefore preferred => this is the right place 3. Everything else should go into another extension
Method | open |
Called before visiting project (i.e. set of modules). |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Class Variable | msgs |
Undocumented |
Class Variable | name |
Name of the provider. |
Class Variable | options |
Options provided by this provider. |
Static Method | _check |
Return True if suggestion for assignment expr should be ignored. |
Static Method | _check |
Check if previous sibling is an assignment with the same name. |
Method | _check |
Check if an assignment expression (walrus operator) can be used. |
Method | _check |
Check if dictionary values can be replaced by Namedtuple or Dataclass. |
Instance Variable | _max |
Undocumented |
Instance Variable | _py38 |
Undocumented |
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 | 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 visit_assign(self, node:
nodes.Assign
):
(source)
¶
Undocumented
def visit_comprehension(self, node:
nodes.Comprehension
):
(source)
¶
Undocumented
def visit_dict(self, node:
nodes.Dict
):
(source)
¶
Undocumented
def visit_for(self, node:
nodes.For
):
(source)
¶
Undocumented
def visit_if(self, node:
nodes.If
):
(source)
¶
Undocumented
def _check_ignore_assignment_expr_suggestion(node:
nodes.If
, name: str|None
) -> bool
:
(source)
¶
Return True if suggestion for assignment expr should be ignored. E.g., in cases where a match statement would be a better fit (multiple conditions).
def _check_prev_sibling_to_if_stmt(prev_sibling:
nodes.NodeNG|None
, name: str|None
) -> TypeGuard[ nodes.Assign|nodes.AnnAssign]
:
(source)
¶
Check if previous sibling is an assignment with the same name. Ignore statements which span multiple lines.
Check if an assignment expression (walrus operator) can be used. For example if an assignment is directly followed by an if statement: >>> x = 2 >>> if x: >>> ... Can be replaced by: >>> if (x := 2): >>> ... Note: Assignment expressions were added in Python 3.8