pylint-django icon indicating copy to clipboard operation
pylint-django copied to clipboard

pylint-django crash when requests-cache is used in a project

Open khamaileon opened this issue 1 year ago • 0 comments

Bug description

When parsing the following:

import requests
import requests_cache


class SessionManager:
    @staticmethod
    def get_session(cache=False):
        if cache:
            session = requests_cache.CachedSession(
                allowable_methods=("GET", "HEAD", "POST"),
            )

        else:
            session = requests.Session()

        return session

Command used

pylint --load-plugins pylint_django --django-settings-module=django_test.settings .

Pylint output

pylint crashed with a ``AstroidError`` and with the following stacktrace:
Traceback (most recent call last):
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 788, in _lint_file
    check_astroid_module(module)
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 1017, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 1069, in _check_astroid_module
    walker.walk(node)
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    self.walk(child)
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    self.walk(child)
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 87, in walk
    callback(astroid)
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint_plugin_utils/__init__.py", line 58, in __call__
    self.augmentation_func(Chain(self.old_method, node), node)
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint_plugin_utils/__init__.py", line 113, in __call__
    if self.test_func(node):
       ^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint_django/augmentations/__init__.py", line 473, in is_model_factory
    if node_is_subclass(parent_class, *parents):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint_django/utils.py", line 27, in node_is_subclass
    if inf != cls and node_is_subclass(inf, *subclass_names):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint_django/utils.py", line 27, in node_is_subclass
    if inf != cls and node_is_subclass(inf, *subclass_names):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint_django/utils.py", line 27, in node_is_subclass
    if inf != cls and node_is_subclass(inf, *subclass_names):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 978 more times]
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint_django/utils.py", line 24, in node_is_subclass
    for inf in base_cls.inferred():
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/astroid/nodes/node_ng.py", line 584, in inferred
    return list(self.infer())
           ^^^^^^^^^^^^^^^^^^
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/astroid/nodes/node_ng.py", line 141, in infer
    context = InferenceContext()
              ^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded

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

Traceback (most recent call last):
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 752, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/Users/me/.virtualenvs/django-test/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 790, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

No crash.

Pylint version

pylint 3.3.1
pylint-django 2.6.1
astroid 3.3.5
Python 3.12.7 (main, Oct  1 2024, 02:05:46) [Clang 15.0.0 (clang-1500.3.9.4)]

khamaileon avatar Nov 15 '24 11:11 khamaileon