Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'Uninferable' object is not iterable #7375

Closed
ultmaster opened this issue Aug 29, 2022 · 4 comments · Fixed by pylint-dev/astroid#1763
Closed

TypeError: 'Uninferable' object is not iterable #7375

ultmaster opened this issue Aug 29, 2022 · 4 comments · Fixed by pylint-dev/astroid#1763
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@ultmaster
Copy link

ultmaster commented Aug 29, 2022

Bug description

When parsing the following file:

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

try:
    from .version import __version__  # pylint: disable=import-error
except ModuleNotFoundError:
    __version__ = '999.dev0'

from .runtime.log import _init_logger
_init_logger()

from .common.framework import *
from .common.serializer import trace, dump, load
from .experiment import Experiment
from .runtime.env_vars import dispatcher_env_vars
from .runtime.log import enable_global_logging, silence_stdout
from .utils import ClassArgsValidator

if dispatcher_env_vars.SDK_PROCESS != 'dispatcher':
    from .trial import *
    from .smartparam import *
    from .common.nas_utils import training_update

class NoMoreTrialError(Exception):
    def __init__(self, ErrorInfo='Search space fully explored'):
        super().__init__(self)
        self.errorinfo = ErrorInfo

    def __str__(self):
        return self.errorinfo

pylint crashed with a AstroidError and with the following stacktrace:

Traceback (most recent call last):
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/inference_tip.py", line 38, in _inference_tip_cached
    result = _cache[func, node]
KeyError: (<function infer_named_tuple at 0x7f3f50baa1f0>, <Call l.31 at 0x7f3f32dfc1f0>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/brain/brain_namedtuple_enum.py", line 88, in infer_func_form
    attributes: list[str] = names.value.replace(",", " ").split()
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/bases.py", line 134, in __getattr__
    return getattr(self._proxied, name)
AttributeError: 'ClassDef' object has no attribute 'value'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vsts/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 769, in _lint_file
    check_astroid_module(module)
  File "/home/vsts/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1029, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/vsts/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1079, in _check_astroid_module
    walker.walk(node)
  File "/home/vsts/.local/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/home/vsts/.local/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "/home/vsts/.local/lib/python3.9/site-packages/pylint/checkers/variables.py", line 1727, in visit_importfrom
    self._check_module_attrs(node, module, name.split("."))
  File "/home/vsts/.local/lib/python3.9/site-packages/pylint/checkers/variables.py", line 2652, in _check_module_attrs
    module = next(module.getattr(name)[0].infer())
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    yield from self._infer(context=context, **kwargs)
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/decorators.py", line 139, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/decorators.py", line 108, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/bases.py", line 165, in _infer_stmts
    for inf in stmt.infer(context=context):  # type: ignore[union-attr]
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 182, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/decorators.py", line 139, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/decorators.py", line 108, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/inference.py", line 264, in infer_call
    yield from callee.infer_call_result(caller=self, context=callcontext)
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 1748, in infer_call_result
    yield from returnnode.value.infer(context)
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 182, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/decorators.py", line 139, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/decorators.py", line 108, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/inference.py", line 255, in infer_call
    for callee in self.func.infer(context):
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 159, in infer
    results = list(self._explicit_inference(self, context, **kwargs))
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/inference_tip.py", line 45, in _inference_tip_cached
    result = _cache[func, node] = list(func(*args, **kwargs))
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/brain/brain_namedtuple_enum.py", line 190, in infer_named_tuple
    class_node, name, attributes = infer_func_form(
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/brain/brain_namedtuple_enum.py", line 93, in infer_func_form
    fields = _get_namedtuple_fields(node)
  File "/home/vsts/.local/lib/python3.9/site-packages/astroid/brain/brain_namedtuple_enum.py", line 541, in _get_namedtuple_fields
    for elt in next(node.args[1].infer()).elts:
TypeError: 'Uninferable' object is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/vsts/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 734, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/home/vsts/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 771, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Configuration

# Usage:
#       python3 -m pylint --rcfile=PATH_TO_THIS_FILE PACKAGE_NAME
# or
#       python3 -m pylint --rcfile=PATH_TO_THIS_FILE SOURCE_FILE.py

[SETTINGS]

max-line-length=140

max-args=8
max-locals=15
max-statements=50
max-attributes=15

const-naming-style=any

# based on pylint 2.1.1
disable=W,C,R,I,no-member

# will be enforced on CI Pipeline
enable= unused-wildcard-import,
        bad-whitespace,
        unused-import,
        bad-continuation,
        wrong-import-order,
        trailing-whitespace,
        logging-not-lazy,
        line-too-long,
        unused-variable,
        wildcard-import,
#        useless-super-delegation,
        len-as-condition,
        logging-format-interpolation,
        redefined-builtin,
        deprecated-method 

# will change to `enable` one day
# disable= missing-docstring

# will not be enforced on CI but highly recommend contributor fixing it
# enable=no-member,
#        too-many-branches,
#        protected-access 

ignore-patterns=test*

# List of members which are set dynamically and missed by pylint inference
generated-members=numpy.*,torch.*,tensorflow.*,pycuda.*,tensorrt.*

ignored-modules=tensorflow,_winapi,msvcrt,tensorrt,pycuda,nni_node

Command used

python -m pylint --rcfile pylintrc nni

Pylint output

************* Module nni
nni/__init__.py:1:0: F0002: nni/__init__.py: Fatal error while checking 'nni/__init__.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/vsts/.cache/pylint/pylint-crash-2022-08-29-07-03-02.txt'. (astroid-error)

Expected behavior

Success.

It used to work with pylint 2.14.5.

Pylint version

pylint 2.15.0
astroid 2.12.4
python 3.9.13

OS / Environment

Ubuntu 20.04

Additional dependencies

https://msrasrg.visualstudio.com/NNIOpenSource/_build/results?buildId=39425&view=logs&j=96944790-a21b-53d9-449f-42de1f10c3f2&t=882d9a50-fcc7-55b5-da21-227b11b9a8bf

@ultmaster ultmaster added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 29, 2022
@DanielNoord DanielNoord added Crash 💥 A bug that makes pylint crash and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 29, 2022
@Pierre-Sassoulas Pierre-Sassoulas added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Aug 29, 2022
@guilhermearaujo

This comment was marked as off-topic.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.1 milestone Aug 29, 2022
@jacobtylerwalls jacobtylerwalls changed the title pylint crashes when upgrading to 2.15 TypeError: 'Uninferable' object is not iterable Aug 30, 2022
@jacobtylerwalls
Copy link
Member

Hi @guilhermearaujo, your issue looks different -- it's coming out of pylint-django, which may or may not be fully tested against pylint 2.15. I'd also give it a retest against astroid 2.12.5, which just went out. I know that's a lot of dependencies to track, but we'd greatly appreciate knowing if astroid 2.12.5 resolves your issue.

@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.15.1, 2.15.2 Sep 1, 2022
@guilhermearaujo
Copy link

guilhermearaujo commented Sep 2, 2022

@jacobtylerwalls I just tested with astroid 2.12.5, it still fails the same way

@jacobtylerwalls
Copy link
Member

Thanks, then it's probably the same issue as pylint-dev/pylint-django#370.

osmocom-gerrit pushed a commit to osmocom/pysim that referenced this issue Sep 5, 2022
pylint v2.15 is crashing, let's fall-back to a known to work v2.14.5.

Change-Id: Ie29be6ec6631ff2b3d8cd6b2dd9ac0ed8f505e4f
Related: pylint-dev/pylint#7375
Related: OS#5668
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.15.3, 2.15.2 Sep 7, 2022
osmocom-gerrit pushed a commit to osmocom/pysim that referenced this issue Sep 14, 2022
This reverts commit 12175d3.

The upstream has fixed the regression:

pylint-dev/pylint#7375

which was actually not in pylint itself but in its dependency:

pylint-dev/astroid#1763
https://github.com/PyCQA/astroid/releases/tag/v2.12.6

Change-Id: I1bf36e0c6db14a10ff4eab57bae238401dbd7fd0
Closes: OS#5668
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants