Dataset Viewer
Auto-converted to Parquet Duplicate
repo
stringclasses
1 value
instance_id
stringlengths
19
23
base_commit
stringclasses
1 value
patch
stringlengths
279
26.7k
hints_text
stringlengths
226
458
test_outcome_summary
stringclasses
8 values
problem_statement
stringlengths
1.69k
3.46k
FAIL_TO_PASS
sequencelengths
1
366
failed_test_details
listlengths
1
366
version
stringclasses
1 value
environment_setup_commit
stringclasses
1 value
pylint-dev_pylint
pylint-dev__pylint8526
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
diff --git a/pylint/extensions/mccabe.py b/pylint/extensions/mccabe.py index 9489f24d6..e78cfa1c2 100644 --- a/pylint/extensions/mccabe.py +++ b/pylint/extensions/mccabe.py @@ -1,212 +1 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt - -"""Module to add McCabe checker class for pylint.""" - -from __future__ import annotations - -from collections.abc import Sequence -from typing import TYPE_CHECKING, Any, TypeVar, Union - -from astroid import nodes -from mccabe import PathGraph as Mccabe_PathGraph -from mccabe import PathGraphingAstVisitor as Mccabe_PathGraphingAstVisitor - -from pylint import checkers -from pylint.checkers.utils import only_required_for_messages -from pylint.interfaces import HIGH - -if TYPE_CHECKING: - from pylint.lint import PyLinter - -_StatementNodes = Union[ - nodes.Assert, - nodes.Assign, - nodes.AugAssign, - nodes.Delete, - nodes.Raise, - nodes.Yield, - nodes.Import, - nodes.Call, - nodes.Subscript, - nodes.Pass, - nodes.Continue, - nodes.Break, - nodes.Global, - nodes.Return, - nodes.Expr, - nodes.Await, -] - -_SubGraphNodes = Union[nodes.If, nodes.Try, nodes.For, nodes.While] -_AppendableNodeT = TypeVar( - "_AppendableNodeT", bound=Union[_StatementNodes, nodes.While, nodes.FunctionDef] -) - - -class PathGraph(Mccabe_PathGraph): # type: ignore[misc] - def __init__(self, node: _SubGraphNodes | nodes.FunctionDef): - super().__init__(name="", entity="", lineno=1) - self.root = node - - -class PathGraphingAstVisitor(Mccabe_PathGraphingAstVisitor): # type: ignore[misc] - def __init__(self) -> None: - super().__init__() - self._bottom_counter = 0 - self.graph: PathGraph | None = None - - def default(self, node: nodes.NodeNG, *args: Any) -> None: - for child in node.get_children(): - self.dispatch(child, *args) - - def dispatch(self, node: nodes.NodeNG, *args: Any) -> Any: - self.node = node - klass = node.__class__ - meth = self._cache.get(klass) - if meth is None: - class_name = klass.__name__ - meth = getattr(self.visitor, "visit" + class_name, self.default) - self._cache[klass] = meth - return meth(node, *args) - - def visitFunctionDef(self, node: nodes.FunctionDef) -> None: - if self.graph is not None: - # closure - pathnode = self._append_node(node) - self.tail = pathnode - self.dispatch_list(node.body) - bottom = f"{self._bottom_counter}" - self._bottom_counter += 1 - self.graph.connect(self.tail, bottom) - self.graph.connect(node, bottom) - self.tail = bottom - else: - self.graph = PathGraph(node) - self.tail = node - self.dispatch_list(node.body) - self.graphs[f"{self.classname}{node.name}"] = self.graph - self.reset() - - visitAsyncFunctionDef = visitFunctionDef - - def visitSimpleStatement(self, node: _StatementNodes) -> None: - self._append_node(node) - - visitAssert = visitAssign = visitAugAssign = visitDelete = visitRaise = ( - visitYield - ) = visitImport = visitCall = visitSubscript = visitPass = visitContinue = ( - visitBreak - ) = visitGlobal = visitReturn = visitExpr = visitAwait = visitSimpleStatement - - def visitWith(self, node: nodes.With) -> None: - self._append_node(node) - self.dispatch_list(node.body) - - visitAsyncWith = visitWith - - def _append_node(self, node: _AppendableNodeT) -> _AppendableNodeT | None: - if not self.tail or not self.graph: - return None - self.graph.connect(self.tail, node) - self.tail = node - return node - - def _subgraph( - self, - node: _SubGraphNodes, - name: str, - extra_blocks: Sequence[nodes.ExceptHandler] = (), - ) -> None: - """Create the subgraphs representing any `if` and `for` statements.""" - if self.graph is None: - # global loop - self.graph = PathGraph(node) - self._subgraph_parse(node, node, extra_blocks) - self.graphs[f"{self.classname}{name}"] = self.graph - self.reset() - else: - self._append_node(node) - self._subgraph_parse(node, node, extra_blocks) - - def _subgraph_parse( - self, - node: _SubGraphNodes, - pathnode: _SubGraphNodes, - extra_blocks: Sequence[nodes.ExceptHandler], - ) -> None: - """Parse the body and any `else` block of `if` and `for` statements.""" - loose_ends = [] - self.tail = node - self.dispatch_list(node.body) - loose_ends.append(self.tail) - for extra in extra_blocks: - self.tail = node - self.dispatch_list(extra.body) - loose_ends.append(self.tail) - if node.orelse: - self.tail = node - self.dispatch_list(node.orelse) - loose_ends.append(self.tail) - else: - loose_ends.append(node) - if node and self.graph: - bottom = f"{self._bottom_counter}" - self._bottom_counter += 1 - for end in loose_ends: - self.graph.connect(end, bottom) - self.tail = bottom - - -class McCabeMethodChecker(checkers.BaseChecker): - """Checks McCabe complexity cyclomatic threshold in methods and functions - to validate a too complex code. - """ - - name = "design" - - msgs = { - "R1260": ( - "%s is too complex. The McCabe rating is %d", - "too-complex", - "Used when a method or function is too complex based on " - "McCabe Complexity Cyclomatic", - ) - } - options = ( - ( - "max-complexity", - { - "default": 10, - "type": "int", - "metavar": "<int>", - "help": "McCabe complexity cyclomatic threshold", - }, - ), - ) - - @only_required_for_messages("too-complex") - def visit_module(self, node: nodes.Module) -> None: - """Visit an astroid.Module node to check too complex rating and - add message if is greater than max_complexity stored from options. - """ - visitor = PathGraphingAstVisitor() - for child in node.body: - visitor.preorder(child, visitor) - for graph in visitor.graphs.values(): - complexity = graph.complexity() - node = graph.root - if hasattr(node, "name"): - node_name = f"'{node.name}'" - else: - node_name = f"This '{node.__class__.__name__.lower()}'" - if complexity <= self.linter.config.max_complexity: - continue - self.add_message( - "too-complex", node=node, confidence=HIGH, args=(node_name, complexity) - ) - - -def register(linter: PyLinter) -> None: - linter.register_checker(McCabeMethodChecker(linter)) +if complexity <= self.linter.config.max_complexity: \ No newline at end of file
The logical condition was changed from checking if complexity is greater than the defined maximum to checking if it is less than or equal to the maximum. This will cause the method not to flag complex methods when it should, leading to failing tests that expect certain complexity ratings to trigger warnings.
4 failed, 325 skipped, 1842 passed.
## Bug Report: IndentationError Causes Unittests to Fail ### Description Several unit tests are failing due to an `IndentationError` in the `mccabe.py` plugin of the Pylint project. The error occurs because the code block following an `if` statement is not properly indented. This bug affects multiple tests where the `mccabe` extension is loaded or utilized. ### Failed Tests 1. **Benchmark Test** - `tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file` 2. **Message ID Store Test** - `tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids` 3. **Functional Test** - `tests/test_functional.py::test_functional[mccabe]` 4. **Callback Options Test** - `tests/test_self.py::TestCallbackOptions::test_enable_all_extensions` ### Unittest Output All the failing tests point to an `IndentationError` in the file `/pylint/pylint/extensions/mccabe.py` with the following trace: ```plaintext File "/pylint/pylint/extensions/mccabe.py", line 1 if complexity <= self.linter.config.max_complexity: ^ IndentationError: expected an indented block after 'if' statement on line 1 ``` ### Suggested Location of the Bug The indentation issue is located in the `mccabe.py` file within the `pylint/extensions` directory. The error suggests that the block following the `if complexity <= self.linter.config.max_complexity:` statement lacks the required indentation, which typically indicates missing code or an improperly formatted block. ### Possible Solutions - **Solution 1**: Review the `mccabe.py` file and ensure that every control statement (such as `if`) is followed by properly indented blocks of code. - **Solution 2**: Verify that any code blocks currently commented out or incorrectly aligned are corrected. - **Solution 3**: If the block is intentionally empty, it should be replaced with a pass statement to denote an empty block: ```python if complexity <= self.linter.config.max_complexity: pass # Placeholder for future logic ``` ### Action Items 1. Inspect the `mccabe.py` file to locate the missing or improperly indented code block. 2. Make the necessary corrections to the indentation and ensure that all blocks of code are valid and logical. 3. Re-run the failing tests after applying the fix to confirm that the issue is resolved. ### Additional Context This error affects tests related to benchmarks, message IDs, functional operation, and callback options, indicating that the bug impacts various functionalities relying on the `mccabe` extension. This suggests that solving the issue will restore multiple facets of unit testing within the Pylint setup.
[ "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "tests/test_functional.py::test_functional[mccabe]", "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions" ]
[ { "nodeid": "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "stack_trace": "self = <test_baseline_benchmarks.TestEstablishBaselineBenchmarks object at 0x14d2d3a44ca0>\nbenchmark = <pytest_benchmark.fixture.BenchmarkFixture object at 0x14d2d2907df0>\n\n def test_baseline_benchmark_j1_all_checks_single_file(\n self, benchmark: BenchmarkFixture\n ) -> None:\n \"\"\"Runs a single file, with -j1, against all checkers/Extensions.\"\"\"\n args = [self.empty_filepath, \"--enable=all\", \"--enable-all-extensions\"]\n> runner = benchmark(Run, args, reporter=Reporter(), exit=False)\n\ntests/benchmark/test_baseline_benchmarks.py:321: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:156: in __call__\n return self._raw(function_to_benchmark, *args, **kwargs)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:180: in _raw\n duration, iterations, loops_range = self._calibrate_timer(runner)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:318: in _calibrate_timer\n duration = runner(loops_range)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:109: in runner\n function_to_benchmark(*args, **kwargs)\npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if complexity <= self.linter.config.max_complexity:', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/mccabe.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/mccabe.py\", line 1\nE if complexity <= self.linter.config.max_complexity:\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "stack_trace": "def test_exclusivity_of_msgids() -> None:\n \"\"\"Test to see if all checkers have an exclusive message id prefix.\"\"\"\n err_msg = (\n \"{} has the same prefix ('{}') as the '{}' checker. Please make sure the prefix \"\n \"is unique for each checker. You can use 'script/get_unused_message_id_category.py' \"\n \"to get a unique id.\"\n )\n> runner = Run([\"--enable-all-extensions\", EMPTY_FILE], exit=False)\n\ntests/message/unittest_message_id_store.py:109: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if complexity <= self.linter.config.max_complexity:', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/mccabe.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/mccabe.py\", line 1\nE if complexity <= self.linter.config.max_complexity:\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_functional.py::test_functional[mccabe]", "stack_trace": "self = <pylint.testutils.lint_module_test.LintModuleTest object at 0x14d2b5103c70>\ntest_file = FunctionalTest:mccabe\nconfig = <_pytest.config.Config object at 0x14d2d5214940>\n\n def __init__(\n self, test_file: FunctionalTestFile, config: Config | None = None\n ) -> None:\n _test_reporter = FunctionalTestReporter()\n self._linter = PyLinter()\n self._linter.config.persistent = 0\n checkers.initialize(self._linter)\n \n # See if test has its own .rc file, if so we use that one\n rc_file: Path | str = PYLINTRC\n try:\n rc_file = test_file.option_file\n self._linter.disable(\"suppressed-message\")\n self._linter.disable(\"locally-disabled\")\n self._linter.disable(\"useless-suppression\")\n except NoFileError:\n pass\n \n self._test_file = test_file\n try:\n args = [test_file.source]\n except NoFileError:\n # If we're still raising NoFileError the actual source file doesn't exist\n args = [\"\"]\n if config and config.getoption(\"minimal_messages_config\"):\n with self._open_source_file() as f:\n messages_to_enable = {msg[1] for msg in self.get_expected_messages(f)}\n # Always enable fatal errors\n messages_to_enable.add(\"astroid-error\")\n messages_to_enable.add(\"fatal\")\n messages_to_enable.add(\"syntax-error\")\n args.extend([\"--disable=all\", f\"--enable={','.join(messages_to_enable)}\"])\n \n # Add testoptions\n self._linter._arg_parser.add_argument(\n \"--min_pyver\", type=parse_python_version, default=(2, 5)\n )\n self._linter._arg_parser.add_argument(\n \"--max_pyver\", type=parse_python_version, default=(4, 0)\n )\n self._linter._arg_parser.add_argument(\n \"--min_pyver_end_position\", type=parse_python_version, default=(3, 8)\n )\n self._linter._arg_parser.add_argument(\n \"--requires\", type=lambda s: [i.strip() for i in s.split(\",\")], default=[]\n )\n self._linter._arg_parser.add_argument(\n \"--except_implementations\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_platforms\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_from_minimal_messages_config\", default=False\n )\n \n> _config_initialization(\n self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter\n )\n\npylint/testutils/lint_module_test.py:102: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if complexity <= self.linter.config.max_complexity:', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/mccabe.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/mccabe.py\", line 1\nE if complexity <= self.linter.config.max_complexity:\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions", "stack_trace": "@staticmethod\n def test_enable_all_extensions() -> None:\n \"\"\"Test to see if --enable-all-extensions does indeed load all extensions.\"\"\"\n # Record all extensions\n plugins = []\n for filename in os.listdir(os.path.dirname(extensions.__file__)):\n if filename.endswith(\".py\") and not filename.startswith(\"_\"):\n plugins.append(f\"pylint.extensions.{filename[:-3]}\")\n \n # Check if they are loaded\n> runner = Run(\n [\"--enable-all-extensions\", join(HERE, \"regrtest_data\", \"empty.py\")],\n exit=False,\n )\n\ntests/test_self.py:1589: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if complexity <= self.linter.config.max_complexity:', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/mccabe.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/mccabe.py\", line 1\nE if complexity <= self.linter.config.max_complexity:\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" } ]
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
pylint-dev_pylint
pylint-dev__pylint42968
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
diff --git a/pylint/extensions/bad_builtin.py b/pylint/extensions/bad_builtin.py index 79cc5d9f4..49172c179 100644 --- a/pylint/extensions/bad_builtin.py +++ b/pylint/extensions/bad_builtin.py @@ -1,65 +1 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt - -"""Checker for deprecated builtins.""" - -from __future__ import annotations - -from typing import TYPE_CHECKING - -from astroid import nodes - -from pylint.checkers import BaseChecker -from pylint.checkers.utils import only_required_for_messages - -if TYPE_CHECKING: - from pylint.lint import PyLinter - -BAD_FUNCTIONS = ["map", "filter"] -# Some hints regarding the use of bad builtins. -LIST_COMP_MSG = "Using a list comprehension can be clearer." -BUILTIN_HINTS = {"map": LIST_COMP_MSG, "filter": LIST_COMP_MSG} - - -class BadBuiltinChecker(BaseChecker): - name = "deprecated_builtins" - msgs = { - "W0141": ( - "Used builtin function %s", - "bad-builtin", - "Used when a disallowed builtin function is used (see the " - "bad-function option). Usual disallowed functions are the ones " - "like map, or filter , where Python offers now some cleaner " - "alternative like list comprehension.", - ) - } - - options = ( - ( - "bad-functions", - { - "default": BAD_FUNCTIONS, - "type": "csv", - "metavar": "<builtin function names>", - "help": "List of builtins function names that should not be " - "used, separated by a comma", - }, - ), - ) - - @only_required_for_messages("bad-builtin") - def visit_call(self, node: nodes.Call) -> None: - if isinstance(node.func, nodes.Name): - name = node.func.name - # ignore the name if it's not a builtin (i.e. not defined in the - # locals nor globals scope) - if not (name in node.frame() or name in node.root()): - if name in self.linter.config.bad_functions: - hint = BUILTIN_HINTS.get(name) - args = f"{name!r}. {hint}" if hint else repr(name) - self.add_message("bad-builtin", node=node, args=args) - - -def register(linter: PyLinter) -> None: - linter.register_checker(BadBuiltinChecker(linter)) +if not (name in node.frame() and name in node.root()): \ No newline at end of file
The modified condition inverts the logic by using `and` instead of `or`, which causes the check to incorrectly bypass the detection of bad functions when the function name exists in either the local or global scope, potentially resulting in missed warnings for disallowed builtins like "map" and "filter".
14 failed, 325 skipped, 1832 passed.
## Bug Report: Failing Unit Tests Due to IndentationError ### Issue Summary Several unit tests are failing due to an `IndentationError` in the `bad_builtin.py` extension file. The affected tests cannot execute because of this syntax error, which prevents the function from being parsed correctly by Python. ### Affected Tests The following tests are all failing due to the same underlying issue: 1. `tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file` 2. `tests/config/pylint_config/test_pylint_config_generate.py::test_generate_interactive_exitcode` 3. `tests/config/pylint_config/test_pylint_config_generate.py::test_format_of_output` 4. `tests/config/pylint_config/test_pylint_config_generate.py::test_writing_to_output_file` 5. `tests/config/pylint_config/test_pylint_config_generate.py::test_writing_minimal_file` 6. `tests/config/pylint_config/test_pylint_config_help.py::test_pylint_config_main_messages` 7. `tests/config/pylint_config/test_run_pylint_config.py::test_invocation_of_pylint_config` 8. `tests/config/test_config.py::test_clear_cache_post_run` 9. `tests/config/test_functional_config_loading.py::test_functional_config_loading` 10. `tests/lint/test_run_pylint.py::test_run_pylint_with_invalid_argument` 11. `tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids` 12. `tests/test_functional.py::test_functional[bad_builtin_extension]` 13. `tests/test_functional.py::test_functional[bad_builtins]` 14. `tests/test_self.py::TestCallbackOptions::test_enable_all_extensions` ### Error Details The error appears to occur consistently in the `bad_builtin.py` file located in the `pylint/extensions/` directory. The specific error message is: ``` IndentationError: expected an indented block after 'if' statement on line 1 File "/path/to/pylint/extensions/bad_builtin.py", line 1 if not (name in node.frame() and name in node.root()): ^ ``` ### Steps to Reproduce 1. Run the unit test suite. 2. Observe the failure of the tests listed above due to the `IndentationError`. ### Suggested Fix - Review the `bad_builtin.py` file in the `pylint/extensions/` directory. - Correct the indentation in this file, ensuring that any block following an `if` statement is properly indented. - Verify that there are no further syntax errors or indentation issues in the file. ### Additional Information - This issue is blocking the execution of multiple test cases. - Correcting the syntax error should allow these tests to execute and report on any underlying logic issues. - It may be beneficial to run a linter or static analysis tool on the entire codebase to catch similar issues. By addressing this `IndentationError`, we can restore the test suite's functionality and enable any necessary further debugging of application logic.
[ "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "tests/config/pylint_config/test_pylint_config_generate.py::test_generate_interactive_exitcode", "tests/config/pylint_config/test_pylint_config_generate.py::test_format_of_output", "tests/config/pylint_config/test_pylint_config_generate.py::test_writing_to_output_file", "tests/config/pylint_config/test_pylint_config_generate.py::test_writing_minimal_file", "tests/config/pylint_config/test_pylint_config_help.py::test_pylint_config_main_messages", "tests/config/pylint_config/test_run_pylint_config.py::test_invocation_of_pylint_config", "tests/config/test_config.py::test_clear_cache_post_run", "tests/config/test_functional_config_loading.py::test_functional_config_loading[setup_cfg/issue_4272/option_in_wrong_section.cfg]", "tests/lint/test_run_pylint.py::test_run_pylint_with_invalid_argument", "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "tests/test_functional.py::test_functional[bad_builtin_extension]", "tests/test_functional.py::test_functional[bad_builtins]", "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions" ]
[ { "nodeid": "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "stack_trace": "self = <test_baseline_benchmarks.TestEstablishBaselineBenchmarks object at 0x1527ecac1870>\nbenchmark = <pytest_benchmark.fixture.BenchmarkFixture object at 0x1527eb8fada0>\n\n def test_baseline_benchmark_j1_all_checks_single_file(\n self, benchmark: BenchmarkFixture\n ) -> None:\n \"\"\"Runs a single file, with -j1, against all checkers/Extensions.\"\"\"\n args = [self.empty_filepath, \"--enable=all\", \"--enable-all-extensions\"]\n> runner = benchmark(Run, args, reporter=Reporter(), exit=False)\n\ntests/benchmark/test_baseline_benchmarks.py:321: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:156: in __call__\n return self._raw(function_to_benchmark, *args, **kwargs)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:180: in _raw\n duration, iterations, loops_range = self._calibrate_timer(runner)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:318: in _calibrate_timer\n duration = runner(loops_range)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:109: in runner\n function_to_benchmark(*args, **kwargs)\npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_generate.py::test_generate_interactive_exitcode", "stack_trace": "monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x1527e8d91c60>\n\n def test_generate_interactive_exitcode(monkeypatch: MonkeyPatch) -> None:\n \"\"\"Check that we exit correctly based on different parameters.\"\"\"\n # Monkeypatch everything we don't want to check in this test\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_format\", lambda: \"toml\"\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_minimal_setting\", lambda: False\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_output_file\",\n lambda: (False, Path()),\n )\n \n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n with pytest.raises(SystemExit) as ex:\n> Run([\"generate\", \"--interactive\"])\n\ntests/config/pylint_config/test_pylint_config_generate.py:36: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_generate.py::test_format_of_output", "stack_trace": "monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x1527e8d13460>\ncapsys = <_pytest.capture.CaptureFixture object at 0x1527e8b26740>\n\n def test_format_of_output(\n monkeypatch: MonkeyPatch, capsys: CaptureFixture[str]\n ) -> None:\n \"\"\"Check that we output the correct format.\"\"\"\n # Monkeypatch everything we don't want to check in this test\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_minimal_setting\", lambda: False\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_output_file\",\n lambda: (False, Path()),\n )\n \n # Set the answers needed for the input() calls\n answers = iter([\"T\", \"toml\", \"TOML\", \"I\", \"INI\", \"TOMLINI\", \"exit()\"])\n monkeypatch.setattr(\"builtins.input\", lambda x: next(answers))\n \n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n # Check 'T'\n> Run([\"generate\", \"--interactive\"], exit=False)\n\ntests/config/pylint_config/test_pylint_config_generate.py:62: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_generate.py::test_writing_to_output_file", "stack_trace": "monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x1527e89d9ed0>\ncapsys = <_pytest.capture.CaptureFixture object at 0x1527e89da050>\n\n def test_writing_to_output_file(\n monkeypatch: MonkeyPatch, capsys: CaptureFixture[str]\n ) -> None:\n \"\"\"Check that we can write to an output file.\"\"\"\n # Monkeypatch everything we don't want to check in this test\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_format\", lambda: \"toml\"\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_minimal_setting\", lambda: False\n )\n \n # Set up a temporary file to write to\n tempfile_name = Path(tempfile.gettempdir()) / \"CONFIG\"\n if tempfile_name.exists():\n os.remove(tempfile_name)\n \n # Set the answers needed for the input() calls\n answers = iter(\n [\n # Don't write to file\n \"no\",\n # Write to file\n \"yes\",\n str(tempfile_name),\n # Don't overwrite file\n \"yes\",\n str(tempfile_name),\n \"misspelled-no\",\n \"no\",\n # Don't overwrite file with default\n \"yes\",\n str(tempfile_name),\n \"\",\n # Overwrite file\n \"yes\",\n str(tempfile_name),\n \"yes\",\n ]\n )\n monkeypatch.setattr(\"builtins.input\", lambda x: next(answers))\n \n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n # Check no writing to file\n> Run([\"generate\", \"--interactive\"], exit=False)\n\ntests/config/pylint_config/test_pylint_config_generate.py:136: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_generate.py::test_writing_minimal_file", "stack_trace": "monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x1527e85577f0>\ncapsys = <_pytest.capture.CaptureFixture object at 0x1527e8557a00>\n\n def test_writing_minimal_file(\n monkeypatch: MonkeyPatch, capsys: CaptureFixture[str]\n ) -> None:\n \"\"\"Check that we can write a minimal file.\"\"\"\n # Monkeypatch everything we don't want to check in this test\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_format\", lambda: \"toml\"\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_output_file\",\n lambda: (False, Path()),\n )\n \n # Set the answers needed for the input() calls\n answers = iter([\"no\", \"yes\"])\n monkeypatch.setattr(\"builtins.input\", lambda x: next(answers))\n \n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n # Check not minimal has comments\n> Run([\"generate\", \"--interactive\"], exit=False)\n\ntests/config/pylint_config/test_pylint_config_generate.py:184: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_help.py::test_pylint_config_main_messages", "stack_trace": "capsys = <_pytest.capture.CaptureFixture object at 0x1527e8999990>\n\n def test_pylint_config_main_messages(capsys: CaptureFixture[str]) -> None:\n \"\"\"Check that the help messages are displayed correctly.\"\"\"\n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n> Run([], exit=False)\n\ntests/config/pylint_config/test_pylint_config_help.py:20: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/config/pylint_config/test_run_pylint_config.py::test_invocation_of_pylint_config", "stack_trace": "capsys = <_pytest.capture.CaptureFixture object at 0x1527e897c070>\n\n def test_invocation_of_pylint_config(capsys: CaptureFixture[str]) -> None:\n \"\"\"Check that the help messages are displayed correctly.\"\"\"\n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n with pytest.raises(SystemExit) as ex:\n> _run_pylint_config([\"\"])\n\ntests/config/pylint_config/test_run_pylint_config.py:21: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/__init__.py:46: in _run_pylint_config\n _PylintConfigRun(argv or sys.argv[1:])\npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/config/test_config.py::test_clear_cache_post_run", "stack_trace": "def test_clear_cache_post_run() -> None:\n modname = \"changing.py\"\n with TemporaryDirectory() as tmp_dir:\n create_files([modname], tmp_dir)\n module = tmp_dir + os.sep + modname\n # Run class does not produce the wanted failure\n # must use LintRun to get pylint.lint.Run\n> run_before_edit = LintRun([module, \"--clear-cache-post-run=y\"], exit=False)\n\ntests/config/test_config.py:198: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/config/test_functional_config_loading.py::test_functional_config_loading[setup_cfg/issue_4272/option_in_wrong_section.cfg]", "stack_trace": "configuration_path = '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/tests/config/functional/setup_cfg/issue_4272/option_in_wrong_section.cfg'\ndefault_configuration = {'additional_builtins': (), 'allow_any_import_level': (), 'allow_global_unused_variables': True, 'allow_reexport_from_package': False, ...}\nfile_to_lint_path = '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/tests/config/file_to_lint.py'\ncapsys = <_pytest.capture.CaptureFixture object at 0x1527e5b76d40>\ncaplog = <_pytest.logging.LogCaptureFixture object at 0x1527e5b93c10>\n\n @pytest.mark.parametrize(\"configuration_path\", CONFIGURATION_PATHS)\n def test_functional_config_loading(\n configuration_path: str,\n default_configuration: PylintConfiguration,\n file_to_lint_path: str,\n capsys: CaptureFixture[str],\n caplog: LogCaptureFixture,\n ) -> None:\n \"\"\"Functional tests for configurations.\"\"\"\n # logging is helpful to see what's expected and why. The output of the\n # program is checked during the test so printing messes with the result.\n caplog.set_level(logging.INFO)\n configuration_path = str(FUNCTIONAL_DIR / configuration_path)\n msg = f\"Wrong result with configuration {configuration_path}\"\n expected_code, expected_output = get_expected_output(\n configuration_path, USER_SPECIFIC_PATH\n )\n expected_loaded_configuration = get_expected_configuration(\n configuration_path, default_configuration\n )\n runner = None # The runner can fail to init if conf is bad enough.\n with warnings.catch_warnings():\n warnings.filterwarnings(\n \"ignore\", message=\"The use of 'MASTER'.*\", category=UserWarning\n )\n try:\n> runner = run_using_a_configuration_file(\n configuration_path, file_to_lint_path\n )\n\ntests/config/test_functional_config_loading.py:91: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/configuration_test.py:147: in run_using_a_configuration_file\n runner = Run(args, exit=False)\npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/lint/test_run_pylint.py::test_run_pylint_with_invalid_argument", "stack_trace": "capsys = <_pytest.capture.CaptureFixture object at 0x1527eb8107f0>\n\n def test_run_pylint_with_invalid_argument(capsys: CaptureFixture[str]) -> None:\n \"\"\"Check that appropriate exit code is used with invalid argument.\"\"\"\n with pytest.raises(SystemExit) as ex:\n> run_pylint([\"--never-use-this\"])\n\ntests/lint/test_run_pylint.py:16: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/__init__.py:34: in run_pylint\n PylintRun(argv or sys.argv[1:])\npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "stack_trace": "def test_exclusivity_of_msgids() -> None:\n \"\"\"Test to see if all checkers have an exclusive message id prefix.\"\"\"\n err_msg = (\n \"{} has the same prefix ('{}') as the '{}' checker. Please make sure the prefix \"\n \"is unique for each checker. You can use 'script/get_unused_message_id_category.py' \"\n \"to get a unique id.\"\n )\n> runner = Run([\"--enable-all-extensions\", EMPTY_FILE], exit=False)\n\ntests/message/unittest_message_id_store.py:109: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_functional.py::test_functional[bad_builtin_extension]", "stack_trace": "self = <pylint.testutils.lint_module_test.LintModuleTest object at 0x1527d11dc940>\ntest_file = FunctionalTest:bad_builtin_extension\nconfig = <_pytest.config.Config object at 0x1527ee290970>\n\n def __init__(\n self, test_file: FunctionalTestFile, config: Config | None = None\n ) -> None:\n _test_reporter = FunctionalTestReporter()\n self._linter = PyLinter()\n self._linter.config.persistent = 0\n checkers.initialize(self._linter)\n \n # See if test has its own .rc file, if so we use that one\n rc_file: Path | str = PYLINTRC\n try:\n rc_file = test_file.option_file\n self._linter.disable(\"suppressed-message\")\n self._linter.disable(\"locally-disabled\")\n self._linter.disable(\"useless-suppression\")\n except NoFileError:\n pass\n \n self._test_file = test_file\n try:\n args = [test_file.source]\n except NoFileError:\n # If we're still raising NoFileError the actual source file doesn't exist\n args = [\"\"]\n if config and config.getoption(\"minimal_messages_config\"):\n with self._open_source_file() as f:\n messages_to_enable = {msg[1] for msg in self.get_expected_messages(f)}\n # Always enable fatal errors\n messages_to_enable.add(\"astroid-error\")\n messages_to_enable.add(\"fatal\")\n messages_to_enable.add(\"syntax-error\")\n args.extend([\"--disable=all\", f\"--enable={','.join(messages_to_enable)}\"])\n \n # Add testoptions\n self._linter._arg_parser.add_argument(\n \"--min_pyver\", type=parse_python_version, default=(2, 5)\n )\n self._linter._arg_parser.add_argument(\n \"--max_pyver\", type=parse_python_version, default=(4, 0)\n )\n self._linter._arg_parser.add_argument(\n \"--min_pyver_end_position\", type=parse_python_version, default=(3, 8)\n )\n self._linter._arg_parser.add_argument(\n \"--requires\", type=lambda s: [i.strip() for i in s.split(\",\")], default=[]\n )\n self._linter._arg_parser.add_argument(\n \"--except_implementations\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_platforms\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_from_minimal_messages_config\", default=False\n )\n \n> _config_initialization(\n self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter\n )\n\npylint/testutils/lint_module_test.py:102: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_functional.py::test_functional[bad_builtins]", "stack_trace": "self = <pylint.testutils.lint_module_test.LintModuleTest object at 0x1527d10a8250>\ntest_file = FunctionalTest:bad_builtins\nconfig = <_pytest.config.Config object at 0x1527ee290970>\n\n def __init__(\n self, test_file: FunctionalTestFile, config: Config | None = None\n ) -> None:\n _test_reporter = FunctionalTestReporter()\n self._linter = PyLinter()\n self._linter.config.persistent = 0\n checkers.initialize(self._linter)\n \n # See if test has its own .rc file, if so we use that one\n rc_file: Path | str = PYLINTRC\n try:\n rc_file = test_file.option_file\n self._linter.disable(\"suppressed-message\")\n self._linter.disable(\"locally-disabled\")\n self._linter.disable(\"useless-suppression\")\n except NoFileError:\n pass\n \n self._test_file = test_file\n try:\n args = [test_file.source]\n except NoFileError:\n # If we're still raising NoFileError the actual source file doesn't exist\n args = [\"\"]\n if config and config.getoption(\"minimal_messages_config\"):\n with self._open_source_file() as f:\n messages_to_enable = {msg[1] for msg in self.get_expected_messages(f)}\n # Always enable fatal errors\n messages_to_enable.add(\"astroid-error\")\n messages_to_enable.add(\"fatal\")\n messages_to_enable.add(\"syntax-error\")\n args.extend([\"--disable=all\", f\"--enable={','.join(messages_to_enable)}\"])\n \n # Add testoptions\n self._linter._arg_parser.add_argument(\n \"--min_pyver\", type=parse_python_version, default=(2, 5)\n )\n self._linter._arg_parser.add_argument(\n \"--max_pyver\", type=parse_python_version, default=(4, 0)\n )\n self._linter._arg_parser.add_argument(\n \"--min_pyver_end_position\", type=parse_python_version, default=(3, 8)\n )\n self._linter._arg_parser.add_argument(\n \"--requires\", type=lambda s: [i.strip() for i in s.split(\",\")], default=[]\n )\n self._linter._arg_parser.add_argument(\n \"--except_implementations\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_platforms\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_from_minimal_messages_config\", default=False\n )\n \n> _config_initialization(\n self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter\n )\n\npylint/testutils/lint_module_test.py:102: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions", "stack_trace": "@staticmethod\n def test_enable_all_extensions() -> None:\n \"\"\"Test to see if --enable-all-extensions does indeed load all extensions.\"\"\"\n # Record all extensions\n plugins = []\n for filename in os.listdir(os.path.dirname(extensions.__file__)):\n if filename.endswith(\".py\") and not filename.startswith(\"_\"):\n plugins.append(f\"pylint.extensions.{filename[:-3]}\")\n \n # Check if they are loaded\n> runner = Run(\n [\"--enable-all-extensions\", join(HERE, \"regrtest_data\", \"empty.py\")],\n exit=False,\n )\n\ntests/test_self.py:1589: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if not (name in node.frame() and name in node.root()):', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/bad_builtin.py\", line 1\nE if not (name in node.frame() and name in node.root()):\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" } ]
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
pylint-dev_pylint
pylint-dev__pylint44322
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
diff --git a/pylint/extensions/consider_ternary_expression.py b/pylint/extensions/consider_ternary_expression.py index 83046ce38..8bd2ef443 100644 --- a/pylint/extensions/consider_ternary_expression.py +++ b/pylint/extensions/consider_ternary_expression.py @@ -1,34 +1,4 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt - -"""Check for if / assign blocks that can be rewritten with if-expressions.""" - -from __future__ import annotations - -from typing import TYPE_CHECKING - -from astroid import nodes - -from pylint.checkers import BaseChecker - -if TYPE_CHECKING: - from pylint.lint import PyLinter - - -class ConsiderTernaryExpressionChecker(BaseChecker): - name = "consider_ternary_expression" - msgs = { - "W0160": ( - "Consider rewriting as a ternary expression", - "consider-ternary-expression", - "Multiple assign statements spread across if/else blocks can be " - "rewritten with a single assignment and ternary expression", - ) - } - - def visit_if(self, node: nodes.If) -> None: - if isinstance(node.parent, nodes.If): +if isinstance(node.parent, nodes.If): return if len(node.body) != 1 or len(node.orelse) != 1: @@ -44,13 +14,9 @@ class ConsiderTernaryExpressionChecker(BaseChecker): if not isinstance(bname, nodes.AssignName) or not isinstance( oname, nodes.AssignName ): - return + continue # Changed 'return' to 'continue' if bname.name != oname.name: return - self.add_message("consider-ternary-expression", node=node) - - -def register(linter: PyLinter) -> None: - linter.register_checker(ConsiderTernaryExpressionChecker(linter)) + self.add_message("consider-ternary-expression", node=node) \ No newline at end of file
The change from `return` to `continue` in the loop logic means that the loop will not exit early if a target is not an instance of `nodes.AssignName`, potentially leading to incorrect behavior as the checker continues processing other targets instead of skipping the entire if/else block. This deviation can cause tests that assume no message should be added in these cases to fail.
4 failed, 325 skipped, 1842 passed.
## Bug Report: IndentationError in `consider_ternary_expression.py` Causes Unittest Failures ### Description Multiple unit tests are failing due to an `IndentationError` in the `consider_ternary_expression.py` file located in the Pylint extensions directory. The affected tests are: - `TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file` - `test_exclusivity_of_msgids` - `test_functional[consider_ternary_expression]` - `TestCallbackOptions::test_enable_all_extensions` ### Error Details `IndentationError` is thrown with the message: ``` unindent does not match any outer indentation level ``` This error occurs consistently on line 4 in `consider_ternary_expression.py`: ```python if len(node.body) != 1 or len(node.orelse) != 1: ``` ### Potential Bug Location The issue appears to be in the initial indentation levels of the `consider_ternary_expression.py` script. Inconsistent indentation in Python scripts often leads to this error. Here’s the file path where the error occurs: ``` /pylint/pylint/extensions/consider_ternary_expression.py ``` ### Steps to Reproduce 1. Execute the affected unit tests listed above. 2. Observe the `IndentationError` in the test outputs. ### Suggested Solution 1. **Check Indentation**: Ensure that the indentation level of all lines in `consider_ternary_expression.py` is consistent. Python typically requires using either all tabs or all spaces for indentation in a single file, with spaces being the common standard. 2. **Lint the Code**: Utilize a linter or an IDE that displays and enforces consistent indentation. Linting the file may reveal additional indentation issues in other parts of the script. 3. **Unit Test Verification**: After correcting the indentation, rerun the affected tests to verify they pass successfully. ### Additional Information Since this error affects multiple tests, ensuring the entire file follows consistent indentation conventions will likely resolve this issue across all failing test cases. If the problem persists after fixing the indentation, further diagnosis of the script's logic may be needed. ### Environment - Python Version: 3.10 - Operating System: Presumed Linux-based environment given file paths This issue requires urgent attention as it affects multiple unit tests, potentially masking additional underlying issues.
[ "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "tests/test_functional.py::test_functional[consider_ternary_expression]", "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions" ]
[ { "nodeid": "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "stack_trace": "self = <test_baseline_benchmarks.TestEstablishBaselineBenchmarks object at 0x14ddf22cc070>\nbenchmark = <pytest_benchmark.fixture.BenchmarkFixture object at 0x14ddf0fcd840>\n\n def test_baseline_benchmark_j1_all_checks_single_file(\n self, benchmark: BenchmarkFixture\n ) -> None:\n \"\"\"Runs a single file, with -j1, against all checkers/Extensions.\"\"\"\n args = [self.empty_filepath, \"--enable=all\", \"--enable-all-extensions\"]\n> runner = benchmark(Run, args, reporter=Reporter(), exit=False)\n\ntests/benchmark/test_baseline_benchmarks.py:321: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:156: in __call__\n return self._raw(function_to_benchmark, *args, **kwargs)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:180: in _raw\n duration, iterations, loops_range = self._calibrate_timer(runner)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:318: in _calibrate_timer\n duration = runner(loops_range)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:109: in runner\n function_to_benchmark(*args, **kwargs)\npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if isinstance(node.parent, nodes.If):\\n return\\n\\n if len(node.body) != 1 or len(node.orelse) != ...node)', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/consider_ternary_expression.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/consider_ternary_expression.py\", line 4\nE if len(node.body) != 1 or len(node.orelse) != 1:\nE ^\nE IndentationError: unindent does not match any outer indentation level\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "stack_trace": "def test_exclusivity_of_msgids() -> None:\n \"\"\"Test to see if all checkers have an exclusive message id prefix.\"\"\"\n err_msg = (\n \"{} has the same prefix ('{}') as the '{}' checker. Please make sure the prefix \"\n \"is unique for each checker. You can use 'script/get_unused_message_id_category.py' \"\n \"to get a unique id.\"\n )\n> runner = Run([\"--enable-all-extensions\", EMPTY_FILE], exit=False)\n\ntests/message/unittest_message_id_store.py:109: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if isinstance(node.parent, nodes.If):\\n return\\n\\n if len(node.body) != 1 or len(node.orelse) != ...node)', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/consider_ternary_expression.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/consider_ternary_expression.py\", line 4\nE if len(node.body) != 1 or len(node.orelse) != 1:\nE ^\nE IndentationError: unindent does not match any outer indentation level\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_functional.py::test_functional[consider_ternary_expression]", "stack_trace": "self = <pylint.testutils.lint_module_test.LintModuleTest object at 0x14ddd5dd37f0>\ntest_file = FunctionalTest:consider_ternary_expression\nconfig = <_pytest.config.Config object at 0x14ddf3aa4970>\n\n def __init__(\n self, test_file: FunctionalTestFile, config: Config | None = None\n ) -> None:\n _test_reporter = FunctionalTestReporter()\n self._linter = PyLinter()\n self._linter.config.persistent = 0\n checkers.initialize(self._linter)\n \n # See if test has its own .rc file, if so we use that one\n rc_file: Path | str = PYLINTRC\n try:\n rc_file = test_file.option_file\n self._linter.disable(\"suppressed-message\")\n self._linter.disable(\"locally-disabled\")\n self._linter.disable(\"useless-suppression\")\n except NoFileError:\n pass\n \n self._test_file = test_file\n try:\n args = [test_file.source]\n except NoFileError:\n # If we're still raising NoFileError the actual source file doesn't exist\n args = [\"\"]\n if config and config.getoption(\"minimal_messages_config\"):\n with self._open_source_file() as f:\n messages_to_enable = {msg[1] for msg in self.get_expected_messages(f)}\n # Always enable fatal errors\n messages_to_enable.add(\"astroid-error\")\n messages_to_enable.add(\"fatal\")\n messages_to_enable.add(\"syntax-error\")\n args.extend([\"--disable=all\", f\"--enable={','.join(messages_to_enable)}\"])\n \n # Add testoptions\n self._linter._arg_parser.add_argument(\n \"--min_pyver\", type=parse_python_version, default=(2, 5)\n )\n self._linter._arg_parser.add_argument(\n \"--max_pyver\", type=parse_python_version, default=(4, 0)\n )\n self._linter._arg_parser.add_argument(\n \"--min_pyver_end_position\", type=parse_python_version, default=(3, 8)\n )\n self._linter._arg_parser.add_argument(\n \"--requires\", type=lambda s: [i.strip() for i in s.split(\",\")], default=[]\n )\n self._linter._arg_parser.add_argument(\n \"--except_implementations\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_platforms\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_from_minimal_messages_config\", default=False\n )\n \n> _config_initialization(\n self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter\n )\n\npylint/testutils/lint_module_test.py:102: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if isinstance(node.parent, nodes.If):\\n return\\n\\n if len(node.body) != 1 or len(node.orelse) != ...node)', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/consider_ternary_expression.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/consider_ternary_expression.py\", line 4\nE if len(node.body) != 1 or len(node.orelse) != 1:\nE ^\nE IndentationError: unindent does not match any outer indentation level\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions", "stack_trace": "@staticmethod\n def test_enable_all_extensions() -> None:\n \"\"\"Test to see if --enable-all-extensions does indeed load all extensions.\"\"\"\n # Record all extensions\n plugins = []\n for filename in os.listdir(os.path.dirname(extensions.__file__)):\n if filename.endswith(\".py\") and not filename.startswith(\"_\"):\n plugins.append(f\"pylint.extensions.{filename[:-3]}\")\n \n # Check if they are loaded\n> runner = Run(\n [\"--enable-all-extensions\", join(HERE, \"regrtest_data\", \"empty.py\")],\n exit=False,\n )\n\ntests/test_self.py:1589: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b'if isinstance(node.parent, nodes.If):\\n return\\n\\n if len(node.body) != 1 or len(node.orelse) != ...node)', '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/consider_ternary_expression.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/consider_ternary_expression.py\", line 4\nE if len(node.body) != 1 or len(node.orelse) != 1:\nE ^\nE IndentationError: unindent does not match any outer indentation level\n\n<frozen importlib._bootstrap>:241: IndentationError" } ]
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
pylint-dev_pylint
pylint-dev__pylint36640
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
diff --git a/pylint/extensions/check_elif.py b/pylint/extensions/check_elif.py index de20ed8ec..4f757f230 100644 --- a/pylint/extensions/check_elif.py +++ b/pylint/extensions/check_elif.py @@ -1,64 +1,3 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt - -from __future__ import annotations - -import tokenize -from tokenize import TokenInfo -from typing import TYPE_CHECKING - -from astroid import nodes - -from pylint.checkers import BaseTokenChecker -from pylint.checkers.utils import only_required_for_messages -from pylint.interfaces import HIGH - -if TYPE_CHECKING: - from pylint.lint import PyLinter - - -class ElseifUsedChecker(BaseTokenChecker): - """Checks for use of "else if" when an "elif" could be used.""" - - name = "else_if_used" - msgs = { - "R5501": ( - 'Consider using "elif" instead of "else" then "if" to remove one indentation level', - "else-if-used", - "Used when an else statement is immediately followed by " - "an if statement and does not contain statements that " - "would be unrelated to it.", - ) - } - - def __init__(self, linter: PyLinter) -> None: - super().__init__(linter) - self._init() - - def _init(self) -> None: - self._elifs: dict[tokenize._Position, str] = {} - - def process_tokens(self, tokens: list[TokenInfo]) -> None: - """Process tokens and look for 'if' or 'elif'.""" - self._elifs = { - begin: token for _, token, begin, _, _ in tokens if token in {"elif", "if"} - } - - def leave_module(self, _: nodes.Module) -> None: - self._init() - - @only_required_for_messages("else-if-used") - def visit_if(self, node: nodes.If) -> None: - """Current if node must directly follow an 'else'.""" - if ( - isinstance(node.parent, nodes.If) - and node.parent.orelse == [node] - and (node.lineno, node.col_offset) in self._elifs - and self._elifs[(node.lineno, node.col_offset)] == "if" - ): - self.add_message("else-if-used", node=node, confidence=HIGH) - - -def register(linter: PyLinter) -> None: - linter.register_checker(ElseifUsedChecker(linter)) +self._elifs = { + begin: token for _, token, begin, _, _ in tokens if token in {"elif", "if"} and _ != 0 + } \ No newline at end of file
The introduced bug ensures that the dictionary `self._elifs` only includes entries for tokens that are not in the first position of the token list. This conditional check `_ != 0` subtly changes the behavior by potentially missing relevant 'if' or 'elif' tokens at the start of the token list, causing the checker logic to fail under certain conditions.
14 failed, 325 skipped, 1832 passed.
### Bug Report: Unittests Failing Due to Undefined Variable 'tokens' #### Problem Description Several unittests are currently failing due to a `NameError` caused by an undefined variable `tokens`. This error occurs when attempting to execute a comprehension involving `tokens` in the `pylint/extensions/check_elif.py` module. The specific line causing the error is: ```python self._elifs = {begin: token for _, token, begin, _, _ in tokens if token in {"elif", "if"} and _ != 0} ``` The following tests are failing: 1. `tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file` 2. `tests/config/pylint_config/test_pylint_config_generate.py::test_generate_interactive_exitcode` 3. `tests/config/pylint_config/test_pylint_config_generate.py::test_format_of_output` 4. `tests/config/pylint_config/test_pylint_config_generate.py::test_writing_to_output_file` 5. `tests/config/pylint_config/test_pylint_config_generate.py::test_writing_minimal_file` 6. `tests/config/pylint_config/test_pylint_config_help.py::test_pylint_config_main_messages` 7. `tests/config/pylint_config/test_run_pylint_config.py::test_invocation_of_pylint_config` 8. `tests/config/test_config.py::test_clear_cache_post_run` 9. `tests/lint/test_run_pylint.py::test_run_pylint_with_invalid_argument` 10. `tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids` 11. `tests/pyreverse/test_pyreverse_functional.py::test_class_diagrams[colorized]` 12. `tests/pyreverse/test_pyreverse_functional.py::test_class_diagrams[custom_colors]` 13. `tests/test_functional.py::test_functional[check_elif]` 14. `tests/test_self.py::TestCallbackOptions::test_enable_all_extensions` #### Suggested Fix The `tokens` variable is not defined within the scope of its usage, resulting in the failure. Possible solutions include: 1. **Define `tokens`:** Ensure that the `tokens` variable is properly defined and initialized before it's used in the comprehension. Verify whether it needs to be passed from another function or module. 2. **Dependency Check:** Check if the `tokens` variable is supposed to be imported from another module or generated by a preceding code section. 3. **Mocking for Tests:** Utilize mocking to simulate the `tokens` input where the test cases are reliant on its presence during tests execution. #### Additional Notes Review other potentially impacted areas of the codebase where `tokens` might be expected to be used. This will ensure that the fix resolves all related issues across the entire project. --- Please address these fixes to restore unittest functionality and ensure that `tokens` is correctly handled throughout the codebase.
[ "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "tests/config/pylint_config/test_pylint_config_generate.py::test_generate_interactive_exitcode", "tests/config/pylint_config/test_pylint_config_generate.py::test_format_of_output", "tests/config/pylint_config/test_pylint_config_generate.py::test_writing_to_output_file", "tests/config/pylint_config/test_pylint_config_generate.py::test_writing_minimal_file", "tests/config/pylint_config/test_pylint_config_help.py::test_pylint_config_main_messages", "tests/config/pylint_config/test_run_pylint_config.py::test_invocation_of_pylint_config", "tests/config/test_config.py::test_clear_cache_post_run", "tests/lint/test_run_pylint.py::test_run_pylint_with_invalid_argument", "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "tests/pyreverse/test_pyreverse_functional.py::test_class_diagrams[colorized]", "tests/pyreverse/test_pyreverse_functional.py::test_class_diagrams[custom_colors]", "tests/test_functional.py::test_functional[check_elif]", "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions" ]
[ { "nodeid": "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "stack_trace": "self = <test_baseline_benchmarks.TestEstablishBaselineBenchmarks object at 0x15284e7913c0>\nbenchmark = <pytest_benchmark.fixture.BenchmarkFixture object at 0x15284d68c400>\n\n def test_baseline_benchmark_j1_all_checks_single_file(\n self, benchmark: BenchmarkFixture\n ) -> None:\n \"\"\"Runs a single file, with -j1, against all checkers/Extensions.\"\"\"\n args = [self.empty_filepath, \"--enable=all\", \"--enable-all-extensions\"]\n> runner = benchmark(Run, args, reporter=Reporter(), exit=False)\n\ntests/benchmark/test_baseline_benchmarks.py:321: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:156: in __call__\n return self._raw(function_to_benchmark, *args, **kwargs)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:180: in _raw\n duration, iterations, loops_range = self._calibrate_timer(runner)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:318: in _calibrate_timer\n duration = runner(loops_range)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:109: in runner\n function_to_benchmark(*args, **kwargs)\npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_generate.py::test_generate_interactive_exitcode", "stack_trace": "monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x15284a8b38b0>\n\n def test_generate_interactive_exitcode(monkeypatch: MonkeyPatch) -> None:\n \"\"\"Check that we exit correctly based on different parameters.\"\"\"\n # Monkeypatch everything we don't want to check in this test\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_format\", lambda: \"toml\"\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_minimal_setting\", lambda: False\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_output_file\",\n lambda: (False, Path()),\n )\n \n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n with pytest.raises(SystemExit) as ex:\n> Run([\"generate\", \"--interactive\"])\n\ntests/config/pylint_config/test_pylint_config_generate.py:36: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_generate.py::test_format_of_output", "stack_trace": "monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x15284a7ff910>\ncapsys = <_pytest.capture.CaptureFixture object at 0x15284a7ff340>\n\n def test_format_of_output(\n monkeypatch: MonkeyPatch, capsys: CaptureFixture[str]\n ) -> None:\n \"\"\"Check that we output the correct format.\"\"\"\n # Monkeypatch everything we don't want to check in this test\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_minimal_setting\", lambda: False\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_output_file\",\n lambda: (False, Path()),\n )\n \n # Set the answers needed for the input() calls\n answers = iter([\"T\", \"toml\", \"TOML\", \"I\", \"INI\", \"TOMLINI\", \"exit()\"])\n monkeypatch.setattr(\"builtins.input\", lambda x: next(answers))\n \n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n # Check 'T'\n> Run([\"generate\", \"--interactive\"], exit=False)\n\ntests/config/pylint_config/test_pylint_config_generate.py:62: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_generate.py::test_writing_to_output_file", "stack_trace": "monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x15284a585150>\ncapsys = <_pytest.capture.CaptureFixture object at 0x15284a584d60>\n\n def test_writing_to_output_file(\n monkeypatch: MonkeyPatch, capsys: CaptureFixture[str]\n ) -> None:\n \"\"\"Check that we can write to an output file.\"\"\"\n # Monkeypatch everything we don't want to check in this test\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_format\", lambda: \"toml\"\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_minimal_setting\", lambda: False\n )\n \n # Set up a temporary file to write to\n tempfile_name = Path(tempfile.gettempdir()) / \"CONFIG\"\n if tempfile_name.exists():\n os.remove(tempfile_name)\n \n # Set the answers needed for the input() calls\n answers = iter(\n [\n # Don't write to file\n \"no\",\n # Write to file\n \"yes\",\n str(tempfile_name),\n # Don't overwrite file\n \"yes\",\n str(tempfile_name),\n \"misspelled-no\",\n \"no\",\n # Don't overwrite file with default\n \"yes\",\n str(tempfile_name),\n \"\",\n # Overwrite file\n \"yes\",\n str(tempfile_name),\n \"yes\",\n ]\n )\n monkeypatch.setattr(\"builtins.input\", lambda x: next(answers))\n \n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n # Check no writing to file\n> Run([\"generate\", \"--interactive\"], exit=False)\n\ntests/config/pylint_config/test_pylint_config_generate.py:136: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_generate.py::test_writing_minimal_file", "stack_trace": "monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x15284a681a50>\ncapsys = <_pytest.capture.CaptureFixture object at 0x15284a681630>\n\n def test_writing_minimal_file(\n monkeypatch: MonkeyPatch, capsys: CaptureFixture[str]\n ) -> None:\n \"\"\"Check that we can write a minimal file.\"\"\"\n # Monkeypatch everything we don't want to check in this test\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_format\", lambda: \"toml\"\n )\n monkeypatch.setattr(\n \"pylint.config._pylint_config.utils.get_and_validate_output_file\",\n lambda: (False, Path()),\n )\n \n # Set the answers needed for the input() calls\n answers = iter([\"no\", \"yes\"])\n monkeypatch.setattr(\"builtins.input\", lambda x: next(answers))\n \n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n # Check not minimal has comments\n> Run([\"generate\", \"--interactive\"], exit=False)\n\ntests/config/pylint_config/test_pylint_config_generate.py:184: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/config/pylint_config/test_pylint_config_help.py::test_pylint_config_main_messages", "stack_trace": "capsys = <_pytest.capture.CaptureFixture object at 0x15284a702260>\n\n def test_pylint_config_main_messages(capsys: CaptureFixture[str]) -> None:\n \"\"\"Check that the help messages are displayed correctly.\"\"\"\n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n> Run([], exit=False)\n\ntests/config/pylint_config/test_pylint_config_help.py:20: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/config/pylint_config/test_run_pylint_config.py::test_invocation_of_pylint_config", "stack_trace": "capsys = <_pytest.capture.CaptureFixture object at 0x15284a1b4730>\n\n def test_invocation_of_pylint_config(capsys: CaptureFixture[str]) -> None:\n \"\"\"Check that the help messages are displayed correctly.\"\"\"\n with warnings.catch_warnings():\n warnings.filterwarnings(\"ignore\", message=\"NOTE:.*\", category=UserWarning)\n with pytest.raises(SystemExit) as ex:\n> _run_pylint_config([\"\"])\n\ntests/config/pylint_config/test_run_pylint_config.py:21: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/__init__.py:46: in _run_pylint_config\n _PylintConfigRun(argv or sys.argv[1:])\npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/config/test_config.py::test_clear_cache_post_run", "stack_trace": "def test_clear_cache_post_run() -> None:\n modname = \"changing.py\"\n with TemporaryDirectory() as tmp_dir:\n create_files([modname], tmp_dir)\n module = tmp_dir + os.sep + modname\n # Run class does not produce the wanted failure\n # must use LintRun to get pylint.lint.Run\n> run_before_edit = LintRun([module, \"--clear-cache-post-run=y\"], exit=False)\n\ntests/config/test_config.py:198: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/lint/test_run_pylint.py::test_run_pylint_with_invalid_argument", "stack_trace": "capsys = <_pytest.capture.CaptureFixture object at 0x15284738ce80>\n\n def test_run_pylint_with_invalid_argument(capsys: CaptureFixture[str]) -> None:\n \"\"\"Check that appropriate exit code is used with invalid argument.\"\"\"\n with pytest.raises(SystemExit) as ex:\n> run_pylint([\"--never-use-this\"])\n\ntests/lint/test_run_pylint.py:16: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/__init__.py:34: in run_pylint\n PylintRun(argv or sys.argv[1:])\npylint/lint/run.py:162: in __init__\n args = _config_initialization(\npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "stack_trace": "def test_exclusivity_of_msgids() -> None:\n \"\"\"Test to see if all checkers have an exclusive message id prefix.\"\"\"\n err_msg = (\n \"{} has the same prefix ('{}') as the '{}' checker. Please make sure the prefix \"\n \"is unique for each checker. You can use 'script/get_unused_message_id_category.py' \"\n \"to get a unique id.\"\n )\n> runner = Run([\"--enable-all-extensions\", EMPTY_FILE], exit=False)\n\ntests/message/unittest_message_id_store.py:109: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/pyreverse/test_pyreverse_functional.py::test_class_diagrams[colorized]", "stack_trace": "testfile = FunctionalPyreverseTestfile(source=PosixPath('/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/tests/pyreverse/func...ns={'source_roots': [], 'output_formats': ['puml'], 'command_line_args': ['-S', '--colorized', '--max-color-depth=2']})\ntmp_path = PosixPath('/tmp/cchoi1/pytest-of-cchoi1/pytest-232/test_class_diagrams_colorized_0')\n\n @pytest.mark.parametrize(\n \"testfile\",\n CLASS_DIAGRAM_TESTS,\n ids=CLASS_DIAGRAM_TEST_IDS,\n )\n def test_class_diagrams(testfile: FunctionalPyreverseTestfile, tmp_path: Path) -> None:\n input_file = testfile.source\n input_path = os.path.dirname(input_file)\n if testfile.options[\"source_roots\"]:\n source_roots = \",\".join(\n [\n os.path.realpath(\n os.path.expanduser(os.path.join(input_path, source_root))\n )\n for source_root in testfile.options[\"source_roots\"]\n ]\n )\n else:\n source_roots = \"\"\n for output_format in testfile.options[\"output_formats\"]:\n args = [\"-o\", f\"{output_format}\", \"-d\", str(tmp_path)]\n if source_roots:\n args += [\"--source-roots\", source_roots]\n args.extend(testfile.options[\"command_line_args\"])\n args += [str(input_file)]\n exit_code = Run(args).run()\n assert exit_code == 0\n> assert testfile.source.with_suffix(f\".{output_format}\").read_text(\n encoding=\"utf8\"\n ) == (tmp_path / f\"classes.{output_format}\").read_text(encoding=\"utf8\")\nE assert '@startuml cl...r2\\n@enduml\\n' == '@startuml cl...r3\\n@enduml\\n'\nE \nE Skipping 144 identical leading characters in diff, use -v to show\nE }\nE + class \"ElseifUsedChecker\" as pylint.extensions.check_elif.ElseifUsedChecker #99DDFF {\nE + msgs : dict\nE + name : str\nE + leave_module(_: nodes.Module) -> None...\nE \nE ...Full output truncated (39 lines hidden), use '-vv' to show\n\ntests/pyreverse/test_pyreverse_functional.py:48: AssertionError" }, { "nodeid": "tests/pyreverse/test_pyreverse_functional.py::test_class_diagrams[custom_colors]", "stack_trace": "testfile = FunctionalPyreverseTestfile(source=PosixPath('/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/tests/pyreverse/func...uml', 'dot'], 'command_line_args': ['-S', '--colorized', '--max-color-depth=2', '--color-palette=red,#44BB88,yellow']})\ntmp_path = PosixPath('/tmp/cchoi1/pytest-of-cchoi1/pytest-232/test_class_diagrams_custom_col0')\n\n @pytest.mark.parametrize(\n \"testfile\",\n CLASS_DIAGRAM_TESTS,\n ids=CLASS_DIAGRAM_TEST_IDS,\n )\n def test_class_diagrams(testfile: FunctionalPyreverseTestfile, tmp_path: Path) -> None:\n input_file = testfile.source\n input_path = os.path.dirname(input_file)\n if testfile.options[\"source_roots\"]:\n source_roots = \",\".join(\n [\n os.path.realpath(\n os.path.expanduser(os.path.join(input_path, source_root))\n )\n for source_root in testfile.options[\"source_roots\"]\n ]\n )\n else:\n source_roots = \"\"\n for output_format in testfile.options[\"output_formats\"]:\n args = [\"-o\", f\"{output_format}\", \"-d\", str(tmp_path)]\n if source_roots:\n args += [\"--source-roots\", source_roots]\n args.extend(testfile.options[\"command_line_args\"])\n args += [str(input_file)]\n exit_code = Run(args).run()\n assert exit_code == 0\n> assert testfile.source.with_suffix(f\".{output_format}\").read_text(\n encoding=\"utf8\"\n ) == (tmp_path / f\"classes.{output_format}\").read_text(encoding=\"utf8\")\nE assert '@startuml cl...r2\\n@enduml\\n' == '@startuml cl...r3\\n@enduml\\n'\nE \nE Skipping 145 identical leading characters in diff, use -v to show\nE }\nE + class \"ElseifUsedChecker\" as pylint.extensions.check_elif.ElseifUsedChecker #44BB88 {\nE + msgs : dict\nE + name : str\nE + leave_module(_: nodes.Module) -> None...\nE \nE ...Full output truncated (39 lines hidden), use '-vv' to show\n\ntests/pyreverse/test_pyreverse_functional.py:48: AssertionError" }, { "nodeid": "tests/test_functional.py::test_functional[check_elif]", "stack_trace": "self = <pylint.testutils.lint_module_test.LintModuleTest object at 0x152832dbada0>\ntest_file = FunctionalTest:check_elif\nconfig = <_pytest.config.Config object at 0x15284ff68970>\n\n def __init__(\n self, test_file: FunctionalTestFile, config: Config | None = None\n ) -> None:\n _test_reporter = FunctionalTestReporter()\n self._linter = PyLinter()\n self._linter.config.persistent = 0\n checkers.initialize(self._linter)\n \n # See if test has its own .rc file, if so we use that one\n rc_file: Path | str = PYLINTRC\n try:\n rc_file = test_file.option_file\n self._linter.disable(\"suppressed-message\")\n self._linter.disable(\"locally-disabled\")\n self._linter.disable(\"useless-suppression\")\n except NoFileError:\n pass\n \n self._test_file = test_file\n try:\n args = [test_file.source]\n except NoFileError:\n # If we're still raising NoFileError the actual source file doesn't exist\n args = [\"\"]\n if config and config.getoption(\"minimal_messages_config\"):\n with self._open_source_file() as f:\n messages_to_enable = {msg[1] for msg in self.get_expected_messages(f)}\n # Always enable fatal errors\n messages_to_enable.add(\"astroid-error\")\n messages_to_enable.add(\"fatal\")\n messages_to_enable.add(\"syntax-error\")\n args.extend([\"--disable=all\", f\"--enable={','.join(messages_to_enable)}\"])\n \n # Add testoptions\n self._linter._arg_parser.add_argument(\n \"--min_pyver\", type=parse_python_version, default=(2, 5)\n )\n self._linter._arg_parser.add_argument(\n \"--max_pyver\", type=parse_python_version, default=(4, 0)\n )\n self._linter._arg_parser.add_argument(\n \"--min_pyver_end_position\", type=parse_python_version, default=(3, 8)\n )\n self._linter._arg_parser.add_argument(\n \"--requires\", type=lambda s: [i.strip() for i in s.split(\",\")], default=[]\n )\n self._linter._arg_parser.add_argument(\n \"--except_implementations\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_platforms\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_from_minimal_messages_config\", default=False\n )\n \n> _config_initialization(\n self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter\n )\n\npylint/testutils/lint_module_test.py:102: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" }, { "nodeid": "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions", "stack_trace": "@staticmethod\n def test_enable_all_extensions() -> None:\n \"\"\"Test to see if --enable-all-extensions does indeed load all extensions.\"\"\"\n # Record all extensions\n plugins = []\n for filename in os.listdir(os.path.dirname(extensions.__file__)):\n if filename.endswith(\".py\") and not filename.startswith(\"_\"):\n plugins.append(f\"pylint.extensions.{filename[:-3]}\")\n \n # Check if they are loaded\n> runner = Run(\n [\"--enable-all-extensions\", join(HERE, \"regrtest_data\", \"empty.py\")],\n exit=False,\n )\n\ntests/test_self.py:1589: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n self._elifs = {\n> begin: token for _, token, begin, _, _ in tokens if token in {\"elif\", \"if\"} and _ != 0\n }\nE NameError: name 'tokens' is not defined\n\npylint/extensions/check_elif.py:2: NameError" } ]
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
pylint-dev_pylint
pylint-dev__pylint43734
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
diff --git a/pylint/extensions/eq_without_hash.py b/pylint/extensions/eq_without_hash.py index 5f39dfa3e..042ab8520 100644 --- a/pylint/extensions/eq_without_hash.py +++ b/pylint/extensions/eq_without_hash.py @@ -1,39 +1,2 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt - -"""This is the remnant of the python3 checker. - -It was removed because the transition from python 2 to python3 is -behind us, but some checks are still useful in python3 after all. -See https://github.com/pylint-dev/pylint/issues/5025 -""" - -from astroid import nodes - -from pylint import checkers, interfaces -from pylint.checkers import utils -from pylint.lint import PyLinter - - -class EqWithoutHash(checkers.BaseChecker): - name = "eq-without-hash" - - msgs = { - "W1641": ( - "Implementing __eq__ without also implementing __hash__", - "eq-without-hash", - "Used when a class implements __eq__ but not __hash__. Objects get " - "None as their default __hash__ implementation if they also implement __eq__.", - ), - } - - @utils.only_required_for_messages("eq-without-hash") - def visit_classdef(self, node: nodes.ClassDef) -> None: - locals_and_methods = set(node.locals).union(x.name for x in node.mymethods()) - if "__eq__" in locals_and_methods and "__hash__" not in locals_and_methods: - self.add_message("eq-without-hash", node=node, confidence=interfaces.HIGH) - - -def register(linter: PyLinter) -> None: - linter.register_checker(EqWithoutHash(linter)) +if "__eq__" not in locals_and_methods and "__hash__" not in locals_and_methods: + self.add_message("eq-without-hash", node=node, confidence=interfaces.HIGH) \ No newline at end of file
The logic bug introduced by checking for `__eq__` not being in `locals_and_methods` instead of checking for its presence causes the checker to incorrectly trigger the "eq-without-hash" message for classes that don't implement `__eq__`, resulting in false positives and failing unit tests that expect correct detection of the issue.
4 failed, 325 skipped, 1842 passed.
## Bug: Failed Unit Tests Due to Undefined `locals_and_methods` Variable ### Description Several unit tests are failing due to a `NameError` indicating that the variable `locals_and_methods` is not defined. This error is consistently occurring in the `pylint/extensions/eq_without_hash.py` file across multiple test files. ### Failing Tests 1. **Benchmark Test:** - `tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file` 2. **Message ID Store Test:** - `tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids` 3. **Functional Test:** - `tests/test_functional.py::test_functional[eq_without_hash]` 4. **Self Test:** - `tests/test_self.py::TestCallbackOptions::test_enable_all_extensions` ### Error Details All test failures include the following stack trace snippet: ```plaintext if "__eq__" not in locals_and_methods and "__hash__" not in locals_and_methods: E NameError: name 'locals_and_methods' is not defined ``` ### Possible Cause The variable `locals_and_methods` is likely intended to be a local collection of identifiers that include class methods or local variables. However, it appears to be undeclared or not initialized correctly in the code, leading to this error. ### Suggested Fix 1. **Ensure Variable Initialization:** - In the `pylint/extensions/eq_without_hash.py` file, confirm that `locals_and_methods` is properly initialized before it is referenced in any conditional checks. - This might involve collecting the desired method names or local variables into a list or set named `locals_and_methods`. 2. **Investigate Initialization Scope:** - Check the function or class scope where `locals_and_methods` is used to ensure it's declared and populated appropriately. ### Additional Notes - Review the design logic in `eq_without_hash.py` to ensure that the intended use of `locals_and_methods` aligns with its purpose. Ensure the logic correctly captures and processes the necessary identifiers. - Verify that any refactor or changes to method checks in this module still allow all intended functionality while resolving the `NameError`. By addressing the variable initialization and ensuring it is correctly declared and populated, the failing tests should pass, restoring the intended functionality.
[ "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "tests/test_functional.py::test_functional[eq_without_hash]", "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions" ]
[ { "nodeid": "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "stack_trace": "self = <test_baseline_benchmarks.TestEstablishBaselineBenchmarks object at 0x1545035153c0>\nbenchmark = <pytest_benchmark.fixture.BenchmarkFixture object at 0x154502219630>\n\n def test_baseline_benchmark_j1_all_checks_single_file(\n self, benchmark: BenchmarkFixture\n ) -> None:\n \"\"\"Runs a single file, with -j1, against all checkers/Extensions.\"\"\"\n args = [self.empty_filepath, \"--enable=all\", \"--enable-all-extensions\"]\n> runner = benchmark(Run, args, reporter=Reporter(), exit=False)\n\ntests/benchmark/test_baseline_benchmarks.py:321: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:156: in __call__\n return self._raw(function_to_benchmark, *args, **kwargs)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:180: in _raw\n duration, iterations, loops_range = self._calibrate_timer(runner)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:318: in _calibrate_timer\n duration = runner(loops_range)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:109: in runner\n function_to_benchmark(*args, **kwargs)\npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n> if \"__eq__\" not in locals_and_methods and \"__hash__\" not in locals_and_methods:\nE NameError: name 'locals_and_methods' is not defined\n\npylint/extensions/eq_without_hash.py:1: NameError" }, { "nodeid": "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "stack_trace": "def test_exclusivity_of_msgids() -> None:\n \"\"\"Test to see if all checkers have an exclusive message id prefix.\"\"\"\n err_msg = (\n \"{} has the same prefix ('{}') as the '{}' checker. Please make sure the prefix \"\n \"is unique for each checker. You can use 'script/get_unused_message_id_category.py' \"\n \"to get a unique id.\"\n )\n> runner = Run([\"--enable-all-extensions\", EMPTY_FILE], exit=False)\n\ntests/message/unittest_message_id_store.py:109: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n> if \"__eq__\" not in locals_and_methods and \"__hash__\" not in locals_and_methods:\nE NameError: name 'locals_and_methods' is not defined\n\npylint/extensions/eq_without_hash.py:1: NameError" }, { "nodeid": "tests/test_functional.py::test_functional[eq_without_hash]", "stack_trace": "self = <pylint.testutils.lint_module_test.LintModuleTest object at 0x1544e4f9bc70>\ntest_file = FunctionalTest:eq_without_hash\nconfig = <_pytest.config.Config object at 0x154504ce0970>\n\n def __init__(\n self, test_file: FunctionalTestFile, config: Config | None = None\n ) -> None:\n _test_reporter = FunctionalTestReporter()\n self._linter = PyLinter()\n self._linter.config.persistent = 0\n checkers.initialize(self._linter)\n \n # See if test has its own .rc file, if so we use that one\n rc_file: Path | str = PYLINTRC\n try:\n rc_file = test_file.option_file\n self._linter.disable(\"suppressed-message\")\n self._linter.disable(\"locally-disabled\")\n self._linter.disable(\"useless-suppression\")\n except NoFileError:\n pass\n \n self._test_file = test_file\n try:\n args = [test_file.source]\n except NoFileError:\n # If we're still raising NoFileError the actual source file doesn't exist\n args = [\"\"]\n if config and config.getoption(\"minimal_messages_config\"):\n with self._open_source_file() as f:\n messages_to_enable = {msg[1] for msg in self.get_expected_messages(f)}\n # Always enable fatal errors\n messages_to_enable.add(\"astroid-error\")\n messages_to_enable.add(\"fatal\")\n messages_to_enable.add(\"syntax-error\")\n args.extend([\"--disable=all\", f\"--enable={','.join(messages_to_enable)}\"])\n \n # Add testoptions\n self._linter._arg_parser.add_argument(\n \"--min_pyver\", type=parse_python_version, default=(2, 5)\n )\n self._linter._arg_parser.add_argument(\n \"--max_pyver\", type=parse_python_version, default=(4, 0)\n )\n self._linter._arg_parser.add_argument(\n \"--min_pyver_end_position\", type=parse_python_version, default=(3, 8)\n )\n self._linter._arg_parser.add_argument(\n \"--requires\", type=lambda s: [i.strip() for i in s.split(\",\")], default=[]\n )\n self._linter._arg_parser.add_argument(\n \"--except_implementations\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_platforms\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_from_minimal_messages_config\", default=False\n )\n \n> _config_initialization(\n self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter\n )\n\npylint/testutils/lint_module_test.py:102: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n> if \"__eq__\" not in locals_and_methods and \"__hash__\" not in locals_and_methods:\nE NameError: name 'locals_and_methods' is not defined\n\npylint/extensions/eq_without_hash.py:1: NameError" }, { "nodeid": "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions", "stack_trace": "@staticmethod\n def test_enable_all_extensions() -> None:\n \"\"\"Test to see if --enable-all-extensions does indeed load all extensions.\"\"\"\n # Record all extensions\n plugins = []\n for filename in os.listdir(os.path.dirname(extensions.__file__)):\n if filename.endswith(\".py\") and not filename.startswith(\"_\"):\n plugins.append(f\"pylint.extensions.{filename[:-3]}\")\n \n # Check if they are loaded\n> runner = Run(\n [\"--enable-all-extensions\", join(HERE, \"regrtest_data\", \"empty.py\")],\n exit=False,\n )\n\ntests/test_self.py:1589: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:883: in exec_module\n ???\n<frozen importlib._bootstrap>:241: in _call_with_frames_removed\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n> if \"__eq__\" not in locals_and_methods and \"__hash__\" not in locals_and_methods:\nE NameError: name 'locals_and_methods' is not defined\n\npylint/extensions/eq_without_hash.py:1: NameError" } ]
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
pylint-dev_pylint
pylint-dev__pylint85726
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
diff --git a/pylint/extensions/redefined_loop_name.py b/pylint/extensions/redefined_loop_name.py index d03b80be3..950b6315e 100644 --- a/pylint/extensions/redefined_loop_name.py +++ b/pylint/extensions/redefined_loop_name.py @@ -1,88 +1 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt - -"""Optional checker to warn when loop variables are overwritten in the loop's body.""" - -from __future__ import annotations - -from astroid import nodes - -from pylint import checkers -from pylint.checkers import utils -from pylint.interfaces import HIGH -from pylint.lint import PyLinter - - -class RedefinedLoopNameChecker(checkers.BaseChecker): - name = "redefined-loop-name" - - msgs = { - "W2901": ( - "Redefining %r from loop (line %s)", - "redefined-loop-name", - "Used when a loop variable is overwritten in the loop body.", - ), - } - - def __init__(self, linter: PyLinter) -> None: - super().__init__(linter) - self._loop_variables: list[ - tuple[nodes.For, list[str], nodes.LocalsDictNodeNG] - ] = [] - - @utils.only_required_for_messages("redefined-loop-name") - def visit_assignname(self, node: nodes.AssignName) -> None: - assign_type = node.assign_type() - if not isinstance(assign_type, (nodes.Assign, nodes.AugAssign)): - return - node_scope = node.scope() - for outer_for, outer_variables, outer_for_scope in self._loop_variables: - if node_scope is not outer_for_scope: - continue - if node.name in outer_variables and not utils.in_for_else_branch( - outer_for, node - ): - self.add_message( - "redefined-loop-name", - args=(node.name, outer_for.fromlineno), - node=node, - confidence=HIGH, - ) - break - - @utils.only_required_for_messages("redefined-loop-name") - def visit_for(self, node: nodes.For) -> None: - assigned_to = [a.name for a in node.target.nodes_of_class(nodes.AssignName)] - # Only check variables that are used - assigned_to = [ - var - for var in assigned_to - if not self.linter.config.dummy_variables_rgx.match(var) - ] - - node_scope = node.scope() - for variable in assigned_to: - for outer_for, outer_variables, outer_for_scope in self._loop_variables: - if node_scope is not outer_for_scope: - continue - if variable in outer_variables and not utils.in_for_else_branch( - outer_for, node - ): - self.add_message( - "redefined-loop-name", - args=(variable, outer_for.fromlineno), - node=node, - confidence=HIGH, - ) - break - - self._loop_variables.append((node, assigned_to, node.scope())) - - @utils.only_required_for_messages("redefined-loop-name") - def leave_for(self, node: nodes.For) -> None: # pylint: disable=unused-argument - self._loop_variables.pop() - - -def register(linter: PyLinter) -> None: - linter.register_checker(RedefinedLoopNameChecker(linter)) +if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'. \ No newline at end of file
The bug introduced changes the condition under which a redefined loop variable message is triggered, causing it to incorrectly report or fail to report variable redefinitions when a 'for' loop is part of a nested structure, leading to false positives or negatives under certain scoped conditions.
5 failed, 325 skipped, 1841 passed.
Title: Indentation Error in `redefined_loop_name.py` Causes Multiple Test Failures ## Description Several unit tests are failing due to an `IndentationError` in the `redefined_loop_name.py` extension file. This error is causing the import process to fail, which subsequently prevents the loading of certain plugins necessary for the tests. ### Failed Tests - `test_baseline_benchmark_j1_all_checks_single_file` in `tests/benchmark/test_baseline_benchmarks.py` - `test_exclusivity_of_msgids` in `tests/message/unittest_message_id_store.py` - `test_functional[redefined_loop_name]` in `tests/test_functional.py` - `test_functional[reused_outer_loop_variable]` in `tests/test_functional.py` - `test_enable_all_extensions` in `tests/test_self.py` ### Error Details The following IndentationError appears in all failed tests: ``` IndentationError: expected an indented block after 'if' statement on line 1 ``` The issue seems to originate from `pylint/pylint/extensions/redefined_loop_name.py`. The first line of the file: ```python if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'. ``` This line lacks an indented block following the `if` statement, leading to the IndentationError. ## Steps to Reproduce 1. Run the unit tests listed under "Failed Tests". 2. Observe the IndentationError during the plugin loading phase for each failed test. ## Suggested Fix - Correct the syntax error in `redefined_loop_name.py` by providing an indented block of code or comment after the `if` statement. - Ensure that `node_scope` and `outer_for_scope` are correctly initialized and used within the expected logic block. ## Additional Notes - Verify the logic within `redefined_loop_name.py` to ensure the change from `not outer_for_scope` to `outer_for_scope` is intentional and functionally correct. - Once the indentation error is fixed, rerun the failing tests to confirm that this resolves the issue. If additional issues arise, they may need separate investigation. ## Environment Information - **Python Version**: 3.10.0 - **Testing Framework**: Pytest By fixing the indentation error, we expect the tests to be able to import the necessary modules and execute without interruptions.
[ "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "tests/test_functional.py::test_functional[redefined_loop_name]", "tests/test_functional.py::test_functional[reused_outer_loop_variable]", "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions" ]
[ { "nodeid": "tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchmark_j1_all_checks_single_file", "stack_trace": "self = <test_baseline_benchmarks.TestEstablishBaselineBenchmarks object at 0x14cc102c8d60>\nbenchmark = <pytest_benchmark.fixture.BenchmarkFixture object at 0x14cc0efc86d0>\n\n def test_baseline_benchmark_j1_all_checks_single_file(\n self, benchmark: BenchmarkFixture\n ) -> None:\n \"\"\"Runs a single file, with -j1, against all checkers/Extensions.\"\"\"\n args = [self.empty_filepath, \"--enable=all\", \"--enable-all-extensions\"]\n> runner = benchmark(Run, args, reporter=Reporter(), exit=False)\n\ntests/benchmark/test_baseline_benchmarks.py:321: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:156: in __call__\n return self._raw(function_to_benchmark, *args, **kwargs)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:180: in _raw\n duration, iterations, loops_range = self._calibrate_timer(runner)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:318: in _calibrate_timer\n duration = runner(loops_range)\nvenv/lib/python3.10/site-packages/pytest_benchmark/fixture.py:109: in runner\n function_to_benchmark(*args, **kwargs)\npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b\"if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\", '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py\", line 1\nE if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/message/unittest_message_id_store.py::test_exclusivity_of_msgids", "stack_trace": "def test_exclusivity_of_msgids() -> None:\n \"\"\"Test to see if all checkers have an exclusive message id prefix.\"\"\"\n err_msg = (\n \"{} has the same prefix ('{}') as the '{}' checker. Please make sure the prefix \"\n \"is unique for each checker. You can use 'script/get_unused_message_id_category.py' \"\n \"to get a unique id.\"\n )\n> runner = Run([\"--enable-all-extensions\", EMPTY_FILE], exit=False)\n\ntests/message/unittest_message_id_store.py:109: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b\"if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\", '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py\", line 1\nE if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_functional.py::test_functional[redefined_loop_name]", "stack_trace": "self = <pylint.testutils.lint_module_test.LintModuleTest object at 0x14cbf17b6a70>\ntest_file = FunctionalTest:redefined_loop_name\nconfig = <_pytest.config.Config object at 0x14cc11a90970>\n\n def __init__(\n self, test_file: FunctionalTestFile, config: Config | None = None\n ) -> None:\n _test_reporter = FunctionalTestReporter()\n self._linter = PyLinter()\n self._linter.config.persistent = 0\n checkers.initialize(self._linter)\n \n # See if test has its own .rc file, if so we use that one\n rc_file: Path | str = PYLINTRC\n try:\n rc_file = test_file.option_file\n self._linter.disable(\"suppressed-message\")\n self._linter.disable(\"locally-disabled\")\n self._linter.disable(\"useless-suppression\")\n except NoFileError:\n pass\n \n self._test_file = test_file\n try:\n args = [test_file.source]\n except NoFileError:\n # If we're still raising NoFileError the actual source file doesn't exist\n args = [\"\"]\n if config and config.getoption(\"minimal_messages_config\"):\n with self._open_source_file() as f:\n messages_to_enable = {msg[1] for msg in self.get_expected_messages(f)}\n # Always enable fatal errors\n messages_to_enable.add(\"astroid-error\")\n messages_to_enable.add(\"fatal\")\n messages_to_enable.add(\"syntax-error\")\n args.extend([\"--disable=all\", f\"--enable={','.join(messages_to_enable)}\"])\n \n # Add testoptions\n self._linter._arg_parser.add_argument(\n \"--min_pyver\", type=parse_python_version, default=(2, 5)\n )\n self._linter._arg_parser.add_argument(\n \"--max_pyver\", type=parse_python_version, default=(4, 0)\n )\n self._linter._arg_parser.add_argument(\n \"--min_pyver_end_position\", type=parse_python_version, default=(3, 8)\n )\n self._linter._arg_parser.add_argument(\n \"--requires\", type=lambda s: [i.strip() for i in s.split(\",\")], default=[]\n )\n self._linter._arg_parser.add_argument(\n \"--except_implementations\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_platforms\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_from_minimal_messages_config\", default=False\n )\n \n> _config_initialization(\n self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter\n )\n\npylint/testutils/lint_module_test.py:102: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b\"if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\", '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py\", line 1\nE if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_functional.py::test_functional[reused_outer_loop_variable]", "stack_trace": "self = <pylint.testutils.lint_module_test.LintModuleTest object at 0x14cbf1503a00>\ntest_file = FunctionalTest:reused_outer_loop_variable\nconfig = <_pytest.config.Config object at 0x14cc11a90970>\n\n def __init__(\n self, test_file: FunctionalTestFile, config: Config | None = None\n ) -> None:\n _test_reporter = FunctionalTestReporter()\n self._linter = PyLinter()\n self._linter.config.persistent = 0\n checkers.initialize(self._linter)\n \n # See if test has its own .rc file, if so we use that one\n rc_file: Path | str = PYLINTRC\n try:\n rc_file = test_file.option_file\n self._linter.disable(\"suppressed-message\")\n self._linter.disable(\"locally-disabled\")\n self._linter.disable(\"useless-suppression\")\n except NoFileError:\n pass\n \n self._test_file = test_file\n try:\n args = [test_file.source]\n except NoFileError:\n # If we're still raising NoFileError the actual source file doesn't exist\n args = [\"\"]\n if config and config.getoption(\"minimal_messages_config\"):\n with self._open_source_file() as f:\n messages_to_enable = {msg[1] for msg in self.get_expected_messages(f)}\n # Always enable fatal errors\n messages_to_enable.add(\"astroid-error\")\n messages_to_enable.add(\"fatal\")\n messages_to_enable.add(\"syntax-error\")\n args.extend([\"--disable=all\", f\"--enable={','.join(messages_to_enable)}\"])\n \n # Add testoptions\n self._linter._arg_parser.add_argument(\n \"--min_pyver\", type=parse_python_version, default=(2, 5)\n )\n self._linter._arg_parser.add_argument(\n \"--max_pyver\", type=parse_python_version, default=(4, 0)\n )\n self._linter._arg_parser.add_argument(\n \"--min_pyver_end_position\", type=parse_python_version, default=(3, 8)\n )\n self._linter._arg_parser.add_argument(\n \"--requires\", type=lambda s: [i.strip() for i in s.split(\",\")], default=[]\n )\n self._linter._arg_parser.add_argument(\n \"--except_implementations\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_platforms\",\n type=lambda s: [i.strip() for i in s.split(\",\")],\n default=[],\n )\n self._linter._arg_parser.add_argument(\n \"--exclude_from_minimal_messages_config\", default=False\n )\n \n> _config_initialization(\n self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter\n )\n\npylint/testutils/lint_module_test.py:102: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/config/config_initialization.py:61: in _config_initialization\n linter.load_plugin_modules(utils._splitstrip(config_data[\"load-plugins\"]))\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b\"if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\", '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py\", line 1\nE if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" }, { "nodeid": "tests/test_self.py::TestCallbackOptions::test_enable_all_extensions", "stack_trace": "@staticmethod\n def test_enable_all_extensions() -> None:\n \"\"\"Test to see if --enable-all-extensions does indeed load all extensions.\"\"\"\n # Record all extensions\n plugins = []\n for filename in os.listdir(os.path.dirname(extensions.__file__)):\n if filename.endswith(\".py\") and not filename.startswith(\"_\"):\n plugins.append(f\"pylint.extensions.{filename[:-3]}\")\n \n # Check if they are loaded\n> runner = Run(\n [\"--enable-all-extensions\", join(HERE, \"regrtest_data\", \"empty.py\")],\n exit=False,\n )\n\ntests/test_self.py:1589: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \npylint/testutils/_run.py:41: in __init__\n super().__init__(args, reporter, exit)\npylint/lint/run.py:155: in __init__\n linter.load_plugin_modules(self._plugins)\npylint/lint/pylinter.py:378: in load_plugin_modules\n module = astroid.modutils.load_module_from_name(modname)\nvenv/lib/python3.10/site-packages/astroid/modutils.py:182: in load_module_from_name\n module = importlib.import_module(dotted_name)\n../../../miniconda3/envs/bugs/lib/python3.10/importlib/__init__.py:126: in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n<frozen importlib._bootstrap>:1050: in _gcd_import\n ???\n<frozen importlib._bootstrap>:1027: in _find_and_load\n ???\n<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked\n ???\n<frozen importlib._bootstrap>:688: in _load_unlocked\n ???\n<frozen importlib._bootstrap_external>:879: in exec_module\n ???\n<frozen importlib._bootstrap_external>:1017: in get_code\n ???\n<frozen importlib._bootstrap_external>:947: in source_to_code\n ???\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nf = <built-in function compile>\nargs = (b\"if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\", '/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py', 'exec')\nkwds = {'dont_inherit': True, 'optimize': -1}\n\n> ???\nE File \"/iris/u/cchoi1/synth_agent_evals/temp_repos2/pylint/pylint/extensions/redefined_loop_name.py\", line 1\nE if node_scope is outer_for_scope: # Changed 'not outer_for_scope' to 'outer_for_scope'.\nE ^\nE IndentationError: expected an indented block after 'if' statement on line 1\n\n<frozen importlib._bootstrap>:241: IndentationError" } ]
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
pylint-dev_pylint
pylint-dev__pylint3
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
"diff --git a/pylint/extensions/no_self_use.py b/pylint/extensions/no_self_use.py\nindex 28a6620a8..(...TRUNCATED)
"The change incorrectly allows methods that are part of `PYMETHODS` to trigger the \"no-self-use\" m(...TRUNCATED)
4 failed, 325 skipped, 1842 passed.
"### Bug Report: Failing Unit Tests Due to `NameError` in `no_self_use.py`\n\n#### Description\n\nSe(...TRUNCATED)
["tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchm(...TRUNCATED)
[{"nodeid":"tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_basel(...TRUNCATED)
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
pylint-dev_pylint
pylint-dev__pylint38536
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
"diff --git a/pylint/extensions/confusing_elif.py b/pylint/extensions/confusing_elif.py\nindex 28754(...TRUNCATED)
"Changing the above line to:\n\n```python\n if node.has_else_block() and body_ends_with_if:\n```\(...TRUNCATED)
4 failed, 325 skipped, 1842 passed.
"Title: IndentationError Causing Unit Test Failures Due to Improperly Defined Code Block\n\n### Desc(...TRUNCATED)
["tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchm(...TRUNCATED)
[{"nodeid":"tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_basel(...TRUNCATED)
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
pylint-dev_pylint
pylint-dev__pylint91685
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
"diff --git a/pylint/__main__.py b/pylint/__main__.py\nindex 448ac55b6..bc2952028 100644\n--- a/pyli(...TRUNCATED)
"The bug introduced in the `pylint.run_pylint()` call by adding `ignore='*.py'` will cause the linte(...TRUNCATED)
1 failed, 325 skipped, 1845 passed.
"### Bug Report: Unit Test Failure in `TestRunTC::test_version`\n\n**Description:**\n\nThe unit test(...TRUNCATED)
[ "tests/test_self.py::TestRunTC::test_version" ]
[{"nodeid":"tests/test_self.py::TestRunTC::test_version","stack_trace":"self = <test_self.TestRunTC (...TRUNCATED)
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
pylint-dev_pylint
pylint-dev__pylint48130
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
"diff --git a/pylint/extensions/for_any_all.py b/pylint/extensions/for_any_all.py\nindex 2369a595d..(...TRUNCATED)
"The modification changes the condition from checking if `if_children` has exactly two elements to n(...TRUNCATED)
12 failed, 325 skipped, 1834 passed.
"### Bug Report: Indentation Error in Pylint Extension\n\n#### Description\nMultiple unittests are f(...TRUNCATED)
["tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_baseline_benchm(...TRUNCATED)
[{"nodeid":"tests/benchmark/test_baseline_benchmarks.py::TestEstablishBaselineBenchmarks::test_basel(...TRUNCATED)
v3.3.1-60-g68cb5b320
68cb5b320653ad64c68ff48a4bb4ba449a01d3a6
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
5