Skip to content

pylint crashes with error "AttributeError: 'str' object has no attribute '_infer_name'" #3306

@Tenyoku8478

Description

@Tenyoku8478

The shortest code I can get to trigger this bug:

_CUSTOM_SCRIPTS = {'echo': lambda x: x} def _generate_message(message): if isinstance(message, list): _, *args = message function_name, *args = args return _CUSTOM_SCRIPTS[function_name](*args) if isinstance(message, str): return message raise TypeError if __name__ == '__main__': assert _generate_message(['function', 'echo', 'test']) == 'test' assert _generate_message('test') == 'test'

Steps to reproduce

  1. Save the code above in test.py
  2. pylint test.py

Current behavior

Traceback (most recent call last): File "/usr/local/bin/pylint", line 10, in <module> sys.exit(run_pylint()) File "/usr/local/lib/python3.7/site-packages/pylint/__init__.py", line 23, in run_pylint PylintRun(sys.argv[1:]) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1731, in __init__ linter.check(args) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1004, in check self._do_check(files_or_modules) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1165, in _do_check self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1252, in check_astroid_module walker.walk(ast_node) File "/usr/local/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 77, in walk self.walk(child) File "/usr/local/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 77, in walk self.walk(child) File "/usr/local/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 77, in walk self.walk(child) File "/usr/local/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 74, in walk callback(astroid) File "/usr/local/lib/python3.7/site-packages/pylint/checkers/base.py", line 2273, in visit_compare self._check_callable_comparison(node) File "/usr/local/lib/python3.7/site-packages/pylint/checkers/base.py", line 2257, in _check_callable_comparison for operand in (left_operand, right_operand) File "/usr/local/lib/python3.7/site-packages/pylint/checkers/base.py", line 2258, in <genexpr> if isinstance(utils.safe_infer(operand), bare_callables) File "/usr/local/lib/python3.7/site-packages/pylint/checkers/utils.py", line 1084, in safe_infer value = next(inferit) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 95, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 227, in infer_call yield from callee.infer_call_result(caller=self, context=callcontext) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 1677, in infer_call_result yield from returnnode.value.infer(context) File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 160, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 113, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 95, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 221, in infer_call for callee in self.func.infer(context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 160, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 113, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 95, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 362, in infer_subscript for index in self.slice.infer(context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 160, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 113, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 160, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 113, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 95, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 133, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 160, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 113, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 95, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 131, in _infer_stmts context.lookupname = stmt._infer_name(frame, name) AttributeError: 'str' object has no attribute '_infer_name' 

Expected behavior

Exit without error.

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.7.3 (default, Mar 27 2019, 09:23:15)
[Clang 10.0.1 (clang-1001.0.46.3)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions