pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.31k stars 1.13k forks source link

TypeError: 'Uninferable' object is not iterable #2434

Closed cdeil closed 6 years ago

cdeil commented 6 years ago

I'm getting this error:

$ make pylint
pylint -E gammapy/ \
    --ignore=_astropy_init.py,gammapy/extern \
    -d E0611,E1101,E1103 \
    --msg-template='{C}: {path}:{line}:{column}: {msg} ({symbol})' -f colorized
************* Module gammapy.__main__
E: gammapy/__main__.py:14:9: No value for argument 'log_level' in function call (no-value-for-parameter)
E: gammapy/__main__.py:14:9: No value for argument 'ignore_warnings' in function call (no-value-for-parameter)
************* Module gammapy.maps.hpx
E: gammapy/maps/hpx.py:9:0: Unable to import 'gammapy.extern.six.moves' (import-error)
************* Module gammapy.maps.wcs
E: gammapy/maps/wcs.py:1086:8: Possible unbalanced tuple unpacking with sequence defined at line 1079: left side has 2 label(s), right side has 3 value(s) (unbalanced-tuple-unpacking)
************* Module gammapy.background.reflected
E: gammapy/background/reflected.py:62:57: bad operand type for unary -: tuple (invalid-unary-operand-type)
E: gammapy/background/reflected.py:62:57: bad operand type for unary -: NoneType (invalid-unary-operand-type)
************* Module gammapy.cube.models
E: gammapy/cube/models.py:184:22: self.spatial_model is not callable (not-callable)
E: gammapy/cube/models.py:185:23: self.spectral_model is not callable (not-callable)
************* Module gammapy.catalog.gammacat
E: gammapy/catalog/gammacat.py:182:18: Too many arguments for format string (too-many-format-args)
Traceback (most recent call last):
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/pylint/__init__.py", line 19, in run_pylint
    Run(sys.argv[1:])
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/pylint/lint.py", line 1394, in __init__
    linter.check(args)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/pylint/lint.py", line 801, in check
    self._do_check(files_or_modules)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/pylint/lint.py", line 938, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/pylint/lint.py", line 1018, in check_astroid_module
    walker.walk(ast_node)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/pylint/utils.py", line 1162, in walk
    self.walk(child)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/pylint/utils.py", line 1159, in walk
    cb(astroid)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/pylint/checkers/imports.py", line 422, in visit_importfrom
    imported_module = self._get_imported_module(node, basename)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/pylint/checkers/imports.py", line 647, in _get_imported_module
    return importnode.do_import_module(modname)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/mixins.py", line 101, in do_import_module
    relative_only=level and level >= 1)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 602, in import_module
    return MANAGER.ast_from_module_name(absmodname)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/manager.py", line 150, in ast_from_module_name
    return self.ast_from_file(found_spec.location, modname, fallback=False)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/manager.py", line 83, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/builder.py", line 128, in file_build
    return self._post_build(module, encoding)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/builder.py", line 145, in _post_build
    self.add_from_names_to_locals(from_node)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/builder.py", line 190, in add_from_names_to_locals
    imported = node.do_import_module()
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/mixins.py", line 101, in do_import_module
    relative_only=level and level >= 1)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 602, in import_module
    return MANAGER.ast_from_module_name(absmodname)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/manager.py", line 150, in ast_from_module_name
    return self.ast_from_file(found_spec.location, modname, fallback=False)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/manager.py", line 83, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/builder.py", line 128, in file_build
    return self._post_build(module, encoding)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/builder.py", line 148, in _post_build
    self.delayed_assattr(delayed)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/builder.py", line 207, in delayed_assattr
    for inferred in node.expr.infer():
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/bases.py", line 125, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/bases.py", line 125, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/inference.py", line 219, in infer_call
    context=callcontext,
  File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 2066, in infer_call_result
    caller, context)
TypeError: 'Uninferable' object is not iterable
make: *** [pylint] Error 1

Version:

(gammapy-dev) hfm-1804a:gammapy deil$ pylint --version
pylint 2.1.1
astroid 2.0.2
Python 3.6.0 | packaged by conda-forge | (default, Feb 10 2017, 07:08:35) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]

This should let you reproduce:

git clone https://github.com/gammapy/gammapy.git
cd gammapy
make pylint
cdeil commented 6 years ago

I still get the same error after pip install pylint astroid --pre -U: https://gist.github.com/cdeil/d82b9c8a058d9a85d53f3d0654500b40

PCManticore commented 6 years ago

Thanks for creating an issue! This should be fixed now in astroid's master.

cdeil commented 6 years ago

@PCManticore - Wow, you fix bugs in < 1 hour after they are reported. Thanks!

Is a bugfix release coming up in the next days, or should I install master?

PCManticore commented 6 years ago

No worries, thanks for the clear report! Probably not this week, so feel free to use master in the meantime, but the plan is to have a pylint 2.2 release by the end of the month.

Hornwitser commented 6 years ago

This doesn't appear to have been fixed. I'm running the latest astroid master (commit 1f0eff526dcc3dea0af68288c719d23767bd2581) and I get

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/.../pylint/pylint/__main__.py", line 7, in <module>
    pylint.run_pylint()
  File "/home/.../pylint/pylint/__init__.py", line 19, in run_pylint
    Run(sys.argv[1:])
  File "/home/.../pylint/pylint/lint.py", line 1394, in __init__
    linter.check(args)
  File "/home/.../pylint/pylint/lint.py", line 801, in check
    self._do_check(files_or_modules)
  File "/home/.../pylint/pylint/lint.py", line 938, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/.../pylint/pylint/lint.py", line 1018, in check_astroid_module
    walker.walk(ast_node)
  File "/home/.../pylint/pylint/utils.py", line 1162, in walk
    self.walk(child)
  File "/home/.../pylint/pylint/utils.py", line 1159, in walk
    cb(astroid)
  File "/home/.../pylint/pylint/checkers/exceptions.py", line 406, in visit_tryexcept
    self._check_try_except_raise(node)
  File "/home/.../pylint/pylint/checkers/exceptions.py", line 384, in _check_try_except_raise
    inferred_current = utils.safe_infer(exc_in_current_handler)
  File "/home/.../pylint/pylint/checkers/utils.py", line 867, in safe_infer
    value = next(inferit)
TypeError: 'Uninferable' object is not an iterator

When running pylint on

import asyncio

try:
    pass
except invalid_name:
    raise
except asyncio.CancelledError:
    pass

And almost identical traceback (only last line differs)

  File "/home/.../pylint/pylint/checkers/utils.py", line 866, in safe_infer
    inferit = node.infer(context=context)
AttributeError: 'NoneType' object has no attribute 'infer'

running pylint on


try:
    pass
except invalid_name:
    raise
except invalid_name:
    pass
PCManticore commented 6 years ago

@Hornwitser From the stack trace, this looks like a completely different problem, albeit involving the same Uninferable object.

PCManticore commented 6 years ago

@Hornwitser The linked pylint commit should fix the problem for you. Make sure to get the latest pylint from github.

Hornwitser commented 6 years ago

Oh, it looked the same to me. Sorry about that. The latest master works, thanks :+1:.

pythonpro7 commented 2 months ago

https://pythoner.space/questions/pylint-reported-an-error-when-trying-to-unpack-a-non-iterable-object