pylint-dev / astroid

A common base representation of python source code for pylint and other projects
https://pylint.readthedocs.io/projects/astroid/en/latest/
GNU Lesser General Public License v2.1
530 stars 275 forks source link

KeyError with pylint 2.6.0 #880

Closed drowlingua closed 3 years ago

drowlingua commented 3 years ago

Steps to reproduce

  1. pylint==2.6.0 and astroid==2.4.2
  2. run pylint some_folder/**

Current behavior

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/astroid/manager.py", line 229, in file_from_module_name
    value = self._mod_file_cache[(modname, contextfile)]
KeyError: ('nt', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/usr/local/lib/python3.6/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/usr/local/lib/python3.6/site-packages/pylint/lint/run.py", line 338, in __init__
    linter.check(args)
  File "/usr/local/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 871, in check
    self.get_ast, self._iterate_file_descrs(files_or_modules)
  File "/usr/local/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 904, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/usr/local/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 930, in _check_file
    check_astroid_module(ast_node)
  File "/usr/local/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 1063, in check_astroid_module
    ast_node, walker, rawcheckers, tokencheckers
  File "/usr/local/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 1107, in _check_astroid_module
    walker.walk(ast_node)
  File "/usr/local/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/usr/local/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/usr/local/lib/python3.6/site-packages/pylint/checkers/variables.py", line 1177, in visit_import
    module = next(_infer_name_module(node, parts[0]))
  File "/usr/local/lib/python3.6/site-packages/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/usr/local/lib/python3.6/site-packages/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.6/site-packages/astroid/decorators.py", line 132, in raise_if_nothing_inferred
    yield next(generator)
  File "/usr/local/lib/python3.6/site-packages/astroid/decorators.py", line 96, in wrapped
    res = next(generator)
  File "/usr/local/lib/python3.6/site-packages/astroid/inference.py", line 254, in infer_import
    yield self.do_import_module(name)
  File "/usr/local/lib/python3.6/site-packages/astroid/mixins.py", line 100, in do_import_module
    modname, level=level, relative_only=level and level >= 1
  File "/usr/local/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 642, in import_module
    return MANAGER.ast_from_module_name(absmodname)
  File "/usr/local/lib/python3.6/site-packages/astroid/manager.py", line 189, in ast_from_module_name
    return self.ast_from_file(found_spec.location, modname, fallback=False)
  File "/usr/local/lib/python3.6/site-packages/astroid/manager.py", line 98, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/usr/local/lib/python3.6/site-packages/astroid/builder.py", line 138, in file_build
    return self._post_build(module, encoding)
  File "/usr/local/lib/python3.6/site-packages/astroid/builder.py", line 155, in _post_build
    self.add_from_names_to_locals(from_node)
  File "/usr/local/lib/python3.6/site-packages/astroid/builder.py", line 209, in add_from_names_to_locals
    imported = node.do_import_module()
  File "/usr/local/lib/python3.6/site-packages/astroid/mixins.py", line 100, in do_import_module
    modname, level=level, relative_only=level and level >= 1
  File "/usr/local/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 642, in import_module
    return MANAGER.ast_from_module_name(absmodname)
  File "/usr/local/lib/python3.6/site-packages/astroid/manager.py", line 145, in ast_from_module_name
    found_spec = self.file_from_module_name(modname, context_file)
  File "/usr/local/lib/python3.6/site-packages/astroid/manager.py", line 233, in file_from_module_name
    modname.split("."), context_file=contextfile
  File "/usr/local/lib/python3.6/site-packages/astroid/modutils.py", line 423, in file_info_from_modpath
    return _spec_from_modpath(modpath, path, context)
  File "/usr/local/lib/python3.6/site-packages/astroid/modutils.py", line 648, in _spec_from_modpath
    found_spec = spec.find_spec(modpath, path)
  File "/usr/local/lib/python3.6/site-packages/astroid/interpreter/_import/spec.py", line 337, in find_spec
    _path, modname, module_parts, processed, submodule_path or path
  File "/usr/local/lib/python3.6/site-packages/astroid/interpreter/_import/spec.py", line 300, in _find_spec_with_path
    spec = finder.find_module(modname, module_parts, processed, submodule_path)
  File "/usr/local/lib/python3.6/site-packages/astroid/interpreter/_import/spec.py", line 192, in find_module
    file_type, filename, path = _search_zip(module_parts, self._zipimporters)
  File "/usr/local/lib/python3.6/site-packages/astroid/interpreter/_import/spec.py", line 281, in _search_zip
    found = importer.find_module(modpath[0])
  File "<frozen importlib._bootstrap_external>", line 423, in _find_module_shim
  File "<frozen importlib._bootstrap_external>", line 1223, in find_loader
  File "<frozen importlib._bootstrap_external>", line 1268, in find_spec
  File "<frozen importlib._bootstrap_external>", line 60, in _path_join
  File "<frozen importlib._bootstrap_external>", line 60, in <listcomp>
AttributeError: 'PosixPath' object has no attribute 'rstrip'

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.4.2

drowlingua commented 3 years ago

This was caused by an incompatibility with the faker library (5.0.2+).