|
18 | 18 |
|
19 | 19 | import astroid |
20 | 20 | from astroid import nodes |
| 21 | +from astroid.typing import InferenceResult |
21 | 22 |
|
22 | 23 | from pylint import constants, interfaces |
23 | 24 | from pylint.checkers import utils |
@@ -199,7 +200,7 @@ class NameChecker(_BasicChecker): |
199 | 200 | ( |
200 | 201 | "good-names", |
201 | 202 | { |
202 | | - "default": ("i", "j", "k", "logger", "ex", "Run", "_"), |
| 203 | + "default": ("i", "j", "k", "ex", "Run", "_"), |
203 | 204 | "type": "csv", |
204 | 205 | "metavar": "<names>", |
205 | 206 | "help": "Good variable names which should always be accepted," |
@@ -399,7 +400,7 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None: |
399 | 400 | "typevar-double-variance", |
400 | 401 | "typevar-name-mismatch", |
401 | 402 | ) |
402 | | - def visit_assignname( # pylint: disable=too-many-branches |
| 403 | + def visit_assignname( # pylint: disable=too-many-branches, too-many-statements |
403 | 404 | self, node: nodes.AssignName |
404 | 405 | ) -> None: |
405 | 406 | """Check module level assigned names.""" |
@@ -477,7 +478,10 @@ def visit_assignname( # pylint: disable=too-many-branches |
477 | 478 | node, (nodes.For, nodes.While) |
478 | 479 | ) |
479 | 480 | ): |
480 | | - self._check_name("const", node.name, node) |
| 481 | + if not self._meets_exception_for_non_consts( |
| 482 | + inferred_assign_type, node.name |
| 483 | + ): |
| 484 | + self._check_name("const", node.name, node) |
481 | 485 | else: |
482 | 486 | node_type = "variable" |
483 | 487 | if ( |
@@ -524,6 +528,17 @@ def visit_assignname( # pylint: disable=too-many-branches |
524 | 528 | else: |
525 | 529 | self._check_name("class_attribute", node.name, node) |
526 | 530 |
|
| 531 | + def _meets_exception_for_non_consts( |
| 532 | + self, inferred_assign_type: InferenceResult | None, name: str |
| 533 | + ) -> bool: |
| 534 | + if isinstance(inferred_assign_type, nodes.Const): |
| 535 | + return False |
| 536 | + if self._name_allowed_by_regex(name=name): |
| 537 | + return True |
| 538 | + regexp = self._name_regexps["variable"] |
| 539 | + match = regexp.match(name) |
| 540 | + return match is not None |
| 541 | + |
527 | 542 | def _recursive_check_names(self, args: list[nodes.AssignName]) -> None: |
528 | 543 | """Check names in a possibly recursive list <arg>.""" |
529 | 544 | for arg in args: |
|
0 commit comments