Skip to content

Compatibility with pylint 3.0 #405

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

Closed
matejsp opened this issue Oct 1, 2023 · 15 comments
Closed

Compatibility with pylint 3.0 #405

matejsp opened this issue Oct 1, 2023 · 15 comments

Comments

@matejsp
Copy link
Contributor

matejsp commented Oct 1, 2023

When trying to test upgrade pylint to 3.0 that will be released in couple of days.

pip install pylint==3.0.0b0
Requirement already satisfied: platformdirs>=2.2.0 in ./.venv/lib/python3.11/site-packages (from pylint==3.0.0b0) (3.10.0)
Requirement already satisfied: isort<6,>=4.2.5 in ./.venv/lib/python3.11/site-packages (from pylint==3.0.0b0) (5.12.0)
Requirement already satisfied: mccabe<0.8,>=0.6 in ./.venv/lib/python3.11/site-packages (from pylint==3.0.0b0) (0.7.0)
Requirement already satisfied: tomlkit>=0.10.1 in ./.venv/lib/python3.11/site-packages (from pylint==3.0.0b0) (0.12.1)
Requirement already satisfied: dill>=0.3.6 in ./.venv/lib/python3.11/site-packages (from pylint==3.0.0b0) (0.3.6)
Installing collected packages: astroid, pylint
  Attempting uninstall: astroid
    Found existing installation: astroid 2.15.6
    Uninstalling astroid-2.15.6:
      Successfully uninstalled astroid-2.15.6
  Attempting uninstall: pylint
    Found existing installation: pylint 2.17.5
    Uninstalling pylint-2.17.5:
      Successfully uninstalled pylint-2.17.5
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pylint-django 2.5.3 requires pylint<3,>=2.0, but you have pylint 3.0.0b0 which is incompatible.
Successfully installed astroid-3.0.0 pylint-3.0.0b0
(.venv) ➜  xxxx pylint .
Traceback (most recent call last):
  File "/Users/myuser/projects/xxxx/.venv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
             ^^^^^^^^^^^^
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/pylint/__init__.py", line 34, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/pylint/lint/run.py", line 162, in __init__
    args = _config_initialization(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/pylint/config/config_initialization.py", line 61, in _config_initialization
    linter.load_plugin_modules(utils._splitstrip(config_data["load-plugins"]))
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 380, in load_plugin_modules
    module = astroid.modutils.load_module_from_name(modname)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/astroid/modutils.py", line 194, in load_module_from_name
    module = importlib.import_module(dotted_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/myuser/.pyenv/versions/3.11.2/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/pylint_django/__init__.py", line 6, in <module>
    from pylint_django import plugin
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/pylint_django/plugin.py", line 9, in <module>
    from pylint_django.checkers import register_checkers
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/pylint_django/checkers/__init__.py", line 2, in <module>
    from pylint_django.checkers.auth_user import AuthUserChecker
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/pylint_django/checkers/auth_user.py", line 7, in <module>
    class AuthUserChecker(checkers.BaseChecker):
  File "/Users/myuser/projects/xxxx/.venv/lib/python3.11/site-packages/pylint_django/checkers/auth_user.py", line 8, in AuthUserChecker
    __implements__ = (interfaces.IAstroidChecker,)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pylint.interfaces' has no attribute 'IAstroidChecker'

NOTES: make sure you have the latest version of 3rd party packages
like rest_framework, factory, model_utils, etc. before reporting
issues!

@carlio
Copy link
Member

carlio commented Oct 1, 2023

Ah, thank you I had not realised pylint 3 was coming out soon. This is going to cause some headaches!

@Pierre-Sassoulas
Copy link
Member

@carlio do you have an opinion on #400 ? I think it could be the first step.

@carlio
Copy link
Member

carlio commented Oct 1, 2023

I agree, I think that I've been clinging on to having as broad a range as possible to be as useful as possible to most people.

However several of the supported Django versions have been end of life even for security updates for more than a year.

I think the sensible thing to do is to release a 3.0 version of pylint-django which drops support for older Django versions. Certainly Django<3. Also removing the python 3.7 support.

I can put a little graph of what versions of (python, pylint, django) are supported and have tags, but it's probably better not to work around people who just don't update their own software, as this causes issues making it harder to keep pylint-django up to date for latest releases.

@Pierre-Sassoulas
Copy link
Member

Let me know if I can help or do not hesitate to take over #400. I don't think there's going to be major incompatibilities with pylint 3.0.0 or anything truly painful to updates but it's hard to know for sure without running the CI first.

carlio pushed a commit that referenced this issue Oct 5, 2023
…move deprecated versions of python/django (#400) and start upgrading to be compatible with python 3.0+ (#405)
@matejsp
Copy link
Contributor Author

matejsp commented Oct 6, 2023

I tried migrating to pylint 3.0.1 and I needed to make the following changes (based on https://pylint.pycqa.org/en/latest/whatsnew/3/3.0/index.html):

Options is now a tuple:

    name_checker = get_checker(linter, NameChecker)
    name_checker.options[0][1]['default'] = name_checker.options[0][1]['default'] + (
        "qs",
        "urlpatterns",
        "register",
        "app_name",
        "handler400",
        "handler403",
        "handler404",
        "handler500",
    )

Replace all @utils.check_messages to @utils.only_required_for_messages.

replace
self.config.django_settings_module
to
self.linter.config.django_settings_module

After that I managed to get it running.
I didn't prepare PR because I don't know if you want to preserve backwards compatibility or just support pylint 3.x

@GTorreil
Copy link

Hello,

Is there a known release date for this ?
Version solving is failing on my projects because of this.

Thanks !

@matejsp
Copy link
Contributor Author

matejsp commented Oct 11, 2023

I have prepared the #407. But I am waiting for maintaner to merge this. @carlio any way to push this forward?

You can test the fix locally:

pip install git+https://github.com/matejsp/pylint-django.git@master

@carlio
Copy link
Member

carlio commented Oct 11, 2023

I am currently on holiday and travelling around so I will do my best to get to it but please be patient!

@GTorreil
Copy link

No worries, thank you ! :)

@carlio
Copy link
Member

carlio commented Oct 22, 2023

Closed via #407 ; pylint-django 2.5.4 is on PyPI

@carlio carlio closed this as completed Oct 22, 2023
@simensol
Copy link

@carlio With pylint 3.0.2 and pylint-django 2.5.4 I still get:

pylint **/*.py
Traceback (most recent call last):
  File "/workspaces/backend/.venv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
             ^^^^^^^^^^^^
  File "/workspaces/backend/.venv/lib/python3.11/site-packages/pylint/__init__.py", line 34, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/workspaces/backend/.venv/lib/python3.11/site-packages/pylint/lint/run.py", line 162, in __init__
    args = _config_initialization(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/backend/.venv/lib/python3.11/site-packages/pylint/config/config_initialization.py", line 61, in _config_initialization
    linter.load_plugin_modules(utils._splitstrip(config_data["load-plugins"]))
  File "/workspaces/backend/.venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 380, in load_plugin_modules
    module = astroid.modutils.load_module_from_name(modname)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/backend/.venv/lib/python3.11/site-packages/astroid/modutils.py", line 194, in load_module_from_name
    module = importlib.import_module(dotted_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/workspaces/backend/.venv/lib/python3.11/site-packages/pylint_django/checkers/migrations.py", line 42, in <module>
    class NewDbFieldWithDefaultChecker(checkers.BaseChecker):
  File "/workspaces/backend/.venv/lib/python3.11/site-packages/pylint_django/checkers/migrations.py", line 54, in NewDbFieldWithDefaultChecker
    __implements__ = (interfaces.IAstroidChecker,)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pylint.interfaces' has no attribute 'IAstroidChecker'

Seems to be related to

__implements__ = (interfaces.IAstroidChecker,)

pylint.interfaces.IAstroidChecker also seems to be used in

__implements__ = (interfaces.IAstroidChecker,)

Maybe related to the following breaking change in pylint 3.0.0:

Everything related to the __implements__ construct was removed. It was based on PEP245 that was proposed in 2001 and rejected in 2006.

@matejsp
Copy link
Contributor Author

matejsp commented Oct 23, 2023

@simensol tnx for the feedback. Somehow I missed this (we are not using django migrations). Prepared another PR.

carlio pushed a commit that referenced this issue Oct 23, 2023
@carlio
Copy link
Member

carlio commented Oct 23, 2023

I have merged the PR, just released 2.5.5 - thanks for pointing it out @simensol and thanks for the quick fix @matejsp !

My fault, this wouldn't have happened if I had fixed the CI but that's underway.

(2.5.4 has been yanked since it doesn't actually run)

@simensol
Copy link

Thanks for the quick response both @matejsp and @carlio! Tested and works on my side.

@andresespinosapc
Copy link

I'm still getting this error on 2.6.1

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

6 participants