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

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

Open
khamaileon opened this issue Nov 15, 2024 · 0 comments
Open

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

khamaileon opened this issue Nov 15, 2024 · 0 comments

Comments

@khamaileon
Copy link

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)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant