Skip to content

Pylint 3 'UninferableBase' object is not iterable #9137

Open

Description

Bug description

When running pylint 3 we have a crash.

The file that crashes, up until line 29:

from __future__ import annotations

import datetime
import logging
import os
import re
import traceback
from collections.abc import Callable
from threading import local
from typing import TYPE_CHECKING

import pytz
import semver
from bson.json_util import loads
from django.conf import settings
from django.core import mail
from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import get_connection
from django.http import HttpResponseForbidden, HttpResponsePermanentRedirect
from django.http.request import HttpRequest
from django.shortcuts import redirect, render
from django.utils.deprecation import MiddlewareMixin as DeprecationMiddlewareMixin
from django.utils.translation import gettext
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
from rest_framework.exceptions import UnsupportedMediaType
from sentry_sdk import configure_scope

from company.apps.companies.managers.company_status import helper_func
from company.libs.json_util import CUSTOM_JSON_OPTIONS

and the code in company.libs.json_util in its entirety:

import pytz
from bson.json_util import LEGACY_JSON_OPTIONS

CUSTOM_JSON_OPTIONS = LEGACY_JSON_OPTIONS.with_options(tz_aware=True, tzinfo=pytz.UTC)

Configuration

No response

Command used

pylint company

Pylint output

Exception on node <ImportFrom l.29 at 0x109b47fd0> in file '/Users/user/code/github.com/company/company/company/libs/middleware/middleware.py'
Traceback (most recent call last):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/pylint/checkers/variables.py", line 2055, in visit_importfrom
    self._check_module_attrs(node, module, name.split("."))
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/pylint/checkers/variables.py", line 3057, in _check_module_attrs
    module = next(module.getattr(name)[0].infer())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 90, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/bases.py", line 179, in _infer_stmts
    for inf in stmt.infer(context=context):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 90, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_classes.py", line 1756, in _infer
    for callee in self.func.infer(context):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 90, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_classes.py", line 1090, in _infer_attribute
    for owner in node.expr.infer(context):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 90, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/bases.py", line 179, in _infer_stmts
    for inf in stmt.infer(context=context):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 90, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/bases.py", line 179, in _infer_stmts
    for inf in stmt.infer(context=context):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 90, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/bases.py", line 179, in _infer_stmts
    for inf in stmt.infer(context=context):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 90, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/node_classes.py", line 1765, in _infer
    yield from callee.infer_call_result(
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2132, in infer_call_result
    if self.is_subtype_of("builtins.type", context) and len(caller.args) == 3:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2069, in is_subtype_of
    return any(anc.qname() == type_name for anc in self.ancestors(context=context))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2069, in <genexpr>
    return any(anc.qname() == type_name for anc in self.ancestors(context=context))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2254, in ancestors
    for grandpa in baseobj.ancestors(recurs=True, context=context):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2254, in ancestors
    for grandpa in baseobj.ancestors(recurs=True, context=context):
  File "/Users/user/code/github.com/company/company/venv/lib/python3.11/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2241, in ancestors
    for baseobj in stmt.infer(context):
TypeError: 'UninferableBase' object is not iterable

Expected behavior

Pylint output without a crash

Pylint version

pylint 3.0.0
astroid 3.0.0
Python 3.11.0 (main, Jun 30 2023, 17:23:40) [Clang 13.0.0 (clang-1300.0.29.30)]

OS / Environment

MacOS 13.5.1 (22G90)

Additional dependencies

agate==1.7.1
amqp==5.1.1
analytics-python==1.2.9
appdirs==1.4.4
appier==1.31.2
Appium-Python-Client==2.2.0
appnope==0.1.3
APScheduler==3.7.0
asgiref==3.7.2
asn1crypto==1.5.1
astroid==3.0.0
asttokens==2.4.0
astunparse==1.6.3
async-generator==1.10
async-timeout==4.0.2
attrs==23.1.0
Authlib==1.2.1
authzed==0.12.0
Babel==2.13.0
backcall==0.2.0
billiard==4.1.0
black==23.9.1
bleach==6.1.0
boto3==1.28.62
botocore==1.31.62
build==1.0.3
cached-property==1.5.2
cachetools==5.3.1
cairocffi==1.6.1
CairoSVG==2.7.1
celery==5.3.4
certifi==2023.7.22
cffi==1.16.0
chardet==5.2.0
charset-normalizer==3.3.0
click==8.1.7
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.3.0
colorama==0.4.6
colorlog==6.7.0
coreapi==2.3.3
coreschema==0.0.4
coverage==7.3.2
cronitor==4.7.0
cryptography==41.0.4
cssselect2==0.7.0
ddt==1.6.0
debugpy==1.8.0
decorator==5.1.1
defusedcsv==1.1.0
defusedxml==0.7.1
Deprecated==1.2.13
dictdiffer==0.9.0
diff-cover==7.7.0
diff-match-patch==20121119
dill==0.3.7
Django==4.2.6
django-admin-confirm==1.0.0
django-appconf==1.0.5
django-compressor==4.4
django-cors-headers==4.2.0
django-csp==3.7
django-csp-reports==1.8.1
django-defender==0.9.7
django-environ==0.11.2
django-filter==23.3
django-js-asset==2.1.0
django-mptt==0.15.0
django-mysql==4.11.0
django-parler==2.3
django-parler-rest==2.2
django-redis==5.4.0
django-storages==1.14.2
djangorestframework==3.14.0
djangosaml2==1.7.0
dnspython==2.3.0
docopt==0.6.2
drf-yasg==1.21.5
dropbox==11.27.0
elasticsearch==7.17.9
elasticsearch-dsl==7.4.1
elementpath==4.1.5
et-xmlfile==1.1.0
eventlet==0.33.3
executing==2.0.0
factory-boy==3.2.1
Faker==13.2.0
fancycompleter==0.9.1
filelock==3.12.4
filetype==1.2.0
flake8==6.1.0
flower==2.0.1
freezegun==1.2.2
furl==2.1.3
geographiclib==2.0
geopy==2.4.0
google-api==0.1.12
google-api-core==2.12.0
google-api-python-client==1.6.6
google-auth==2.23.2
googleapis-common-protos==1.60.0
googlemaps==3.1.4
greenlet==3.0.0
grpcio==1.59.0
gunicorn==21.2.0
h11==0.14.0
html-testRunner==1.2.1
html5lib==1.1
httplib2==0.19.0
humanize==4.8.0
idna==3.4
inflection==0.5.1
iniconfig==2.0.0
ipython==8.16.1
ipython-genutils==0.2.0
iso3166==1.0.1
isodate==0.6.1
isort==5.12.0
itypes==1.2.0
jedi==0.19.1
Jinja2==3.1.2
jmespath==1.0.1
jsons==1.6.3
jsonschema==3.2.0
kombu==5.3.2
leather==0.3.4
libcst==1.0.1
lxml==4.9.3
markdown-it-py==3.0.0
MarkupSafe==2.1.3
matplotlib-inline==0.1.6
mccabe==0.7.0
mdurl==0.1.2
mock==4.0.3
MonkeyType==23.3.0
moto==4.2.5
mypy==1.5.1
mypy-extensions==1.0.0
mysqlclient==2.1.0
ndjson==0.3.1
newrelic==9.1.0
numpy==1.26.0
oauth2client==4.1.3
odfpy==1.4.1
openpyxl==3.0.9
orderedmultidict==1.0.1
orjson==3.9.7
oscrypto==1.3.0
outcome==1.2.0
packaging==23.2
pandas==2.0.3
pandas-schema==0.3.6
parsedatetime==2.6
parso==0.8.3
pathspec==0.11.2
pdbpp==0.10.3
petl==1.7.9
pexpect==4.8.0
phonenumbers==8.13.22
pickleshare==0.7.5
Pillow==10.0.1
pip-tools==7.3.0
platformdirs==3.11.0
pluggy==1.3.0
ply==3.11
pook==1.1.1
prometheus-client==0.17.1
prompt-toolkit==3.0.39
protobuf==4.21.12
protoc-gen-validate==0.10.1
psutil==5.9.5
psycopg2-binary==2.9.9
ptyprocess==0.7.0
pure-eval==0.2.2
pyarrow==10.0.1
pyasn1==0.5.0
pyasn1-modules==0.3.0
pycodestyle==2.11.0
pycountry==22.3.5
pycparser==2.21
pycryptodomex==3.19.0
pydeps==1.12.17
pyflakes==3.1.0
Pygments==2.16.1
PyJWT==2.8.0
pylint==3.0.0
pymongo==4.5.0
pyOpenSSL==23.2.0
pyparsing==2.4.7
PyPDF2==3.0.1
pyphen==0.14.0
pyproject_hooks==1.0.0
pypushwoosh==0.3.0
pyrepl==0.9.0
pyrsistent==0.19.3
pysaml2==7.4.2
PySocks==1.7.1
pytest==7.4.2
pytest-flakefinder==1.1.0
pytest-repeat==0.9.2
pytest-rerunfailures==11.0
pytest-watch==4.2.0
python-dateutil==2.8.2
python-dotenv==1.0.0
python-http-client==3.3.7
python-slugify==8.0.1
pytimeparse==1.1.8
pytz==2023.3.post1
pyupgrade==3.15.0
PyYAML==6.0.1
rcssmin==1.1.1
redis==5.0.1
regex==2023.10.3
requests==2.31.0
requests-futures==1.0.1
requests-toolbelt==1.0.0
responses==0.23.3
rich==13.6.0
rjsmin==1.2.1
rsa==4.9
ruamel.yaml==0.17.35
ruamel.yaml.clib==0.2.8
s3transfer==0.7.0
selenium==4.9.1
selenium-testing-library==2023.7
semver==2.13.0
sendgrid==4.0.0
sentry-sdk==1.31.0
sh==2.0.6
simple-salesforce==1.11.2
six==1.16.0
sniffio==1.3.0
snowflake-connector-python==3.2.1
sortedcontainers==2.4.0
sqlfluff==2.3.2
sqlparse==0.4.4
stack-data==0.6.3
stdlib-list==0.9.0
stone==3.3.1
StrEnum==0.4.15
tablib==0.12.1
tblib==2.0.0
tenacity==8.2.3
testrail-api==1.12.1
text-unidecode==1.3
tinycss2==1.2.1
tokenize-rt==5.2.0
tomlkit==0.12.1
toposort==1.6
tornado==6.3.3
tqdm==4.66.1
traitlets==5.11.2
translate-toolkit==2.2.4
trio==0.22.2
trio-websocket==0.11.1
twilio==6.12.0
types-bleach==6.0.0.5
types-certifi==2021.10.8.3
types-cryptography==3.3.23.2
types-Deprecated==1.2.9.3
types-enum34==1.1.8
types-freezegun==1.1.10
types-ipaddress==1.0.8
types-orjson==3.6.2
types-pyOpenSSL==23.2.0.2
types-python-dateutil==2.8.19.14
types-pytz==2023.3.1.1
types-PyYAML==6.0.12.12
types-redis==4.6.0.7
types-requests==2.31.0.6
types-six==1.16.21.9
types-toml==0.10.8.7
types-tzlocal==5.1.0.0
types-urllib3==1.26.25.14
typing-inspect==0.9.0
typing_extensions==4.8.0
typish==1.9.3
tzdata==2023.3
tzlocal==2.1
ua-parser==0.18.0
unicodecsv==0.14.1
unittest-xml-reporting==3.2.0
uritemplate==3.0.1
urllib3==1.26.17
user-agents==2.1
validate-email==1.3
vine==5.0.0
waiting==1.4.1
watchdog==3.0.0
wcwidth==0.2.8
WeasyPrint==52.5
webencodings==0.5.1
Werkzeug==3.0.0
wmctrl==0.5
wrapt==1.15.0
wsproto==1.2.0
xlrd==2.0.1
XlsxWriter==3.0.2
xlwt==1.3.0
xmlschema==2.5.0
xmltodict==0.13.0
zeep==3.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Crash 💥A bug that makes pylint crashNeeds reproduction 🔍Need a way to reproduce it locally on a maintainer's machine

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions