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

>= not supported between instances of NoneType and tuple when using 2.12.1 version #5424

Closed
JinLisek opened this issue Nov 28, 2021 · 3 comments
Labels
Bug 🪲 Downstream Bug 🪲 The problem happens in a lib depending on pylint, not pylint

Comments

@JinLisek
Copy link

JinLisek commented Nov 28, 2021

Bug description

It's my first issue, so be gentle. ;)

When I run prospector (which runs pylint) with version of pylint: 2.12.1 I get an error:

  File "/home/jinlisek/venvs_py/ahoy2/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1151, in _astroid_module_checker
    checker.open()
  File "/home/jinlisek/venvs_py/ahoy2/lib/python3.9/site-packages/pylint/checkers/unsupported_version.py", line 68, in open
    self._py36_plus = py_version >= (3, 6)

The same configuration I use works fine when I change pylint version to 2.11.1 in requirements.txt

I tried to figure what's going on, on my own. So far, I modified get_global_option in pylint/utils/utils.py by adding below code (had to raise an error, for some reason printing doesn't work for me there):

if "py-version" in option:
  raise RuntimeError(
    f"get_global_option -- option: {option}, checker.config: {checker.config}, checker.linter.config: {checker.linter.config}")

And the output I get is this:

RuntimeError: get_global_option -- option: py-version, checker.config: {}, checker.linter.config: {'black_list': ('CVS', 'migrations', 'south_migrations'), 'black_list_re': [], 'ignore_paths': [], 'persistent': True, 'load_plugins': (), 'output_format': 'text', 'reports': False, 'evaluation': '10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)', 'score': True, 'fail_under': 10.0, 'fail_on': [], 'confidence': [], 'enable': [['file-ignored'], ['suppressed-message']], 'disable': [['empty-docstring'], ['missing-module-docstring'], ['missing-class-docstring'], ['missing-function-docstring'], ['no-name-in-module'], ['no-member'], ['locally-disabled'], ['deprecated-pragma'], ['duplicate-code'], ['too-few-public-methods'], ['fixme']], 'msg_template': None, 'jobs': 1, 'unsafe_load_any_extension': True, 'limit_inference_results': 100, 'extension_pkg_allow_list': [], 'extension_pkg_whitelist': [], 'suggestion_mode': True, 'exit_zero': 0, 'from_stdin': 0, 'py_version': (3, 9)}

You can see that checker.config doesn't contain py_version, but checker.linter.config does contain py_version.

Because checker.config has no py_version member, getattr raises AttributeError.
The error is caught, then pylint checks options_providers, looking for py-version, but it never finds any in options providers. The default value (None) is returned. The flow goes back to UnsupportedVersionChecker::open and when it tries to compare py_version it raises the exception ">= not supported between NoneType and tuple" (due to py_version being None).

It seems that when I modify UnsupportedVersionChecker in pylint/checkers/unsupported_version.py with:

import sys
# other imports

class UnsupportedVersionChecker(BaseChecker):
# other UnsupportedVersionChecker members

    options = (
        (
            "py-version",
            {
                "default": sys.version_info[:2],
                "type": "py_version",
                "metavar": "<py_version>",
                "help": (
                    "Minimum Python version to use for version dependent checks. "
                    "Will default to the version used to run pylint."
                ),
            },
        ),
    )

then pylint works as expected.

AFAIK there was no unsupported_version checker in v2.11.1. It seems that other checkers don't produce errors when trying to get py-version, so my assumption is that unsupported_version is not correctly connected to options system.

Configuration

No response

Command used

DJANGO_SETTINGS_MODULE=ahoy_backend.settings DJANGO_SECRET_KEY=lol prospector --uses django -X

Pylint output

File "/home/jinlisek/venvs_py/ahoy2/bin/prospector", line 8, in <module>
    sys.exit(main())
  File "/home/jinlisek/venvs_py/ahoy2/lib/python3.9/site-packages/prospector/run.py", line 183, in main
    prospector.execute()
  File "/home/jinlisek/venvs_py/ahoy2/lib/python3.9/site-packages/prospector/run.py", line 69, in execute
    messages += tool.run(found_files)
  File "/home/jinlisek/venvs_py/ahoy2/lib/python3.9/site-packages/prospector/tools/pylint/__init__.py", line 259, in run
    self._linter.check(self._args)
  File "/home/jinlisek/venvs_py/ahoy2/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 997, in check
    self._check_files(
  File "/home/jinlisek/venvs_py/ahoy2/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1032, in _check_files
    with self._astroid_module_checker() as check_astroid_module:
  File "/usr/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/home/jinlisek/venvs_py/ahoy2/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1151, in _astroid_module_checker
    checker.open()
  File "/home/jinlisek/venvs_py/ahoy2/lib/python3.9/site-packages/pylint/checkers/unsupported_version.py", line 68, in open
    self._py36_plus = py_version >= (3, 6)

Expected behavior

I would expect pylint to be run correctly, instead of raising an error

Pylint version

pylint 2.12.1
astroid 2.9.0
Python 3.9.7 (default, Aug 31 2021, 13:28:12) 
[GCC 11.1.0]

OS / Environment

No response

Additional dependencies

aioredis==1.3.1
appdirs==1.4.4
asgiref==3.4.1
astroid==2.9.0
async-timeout==4.0.1
attrs==21.2.0
autobahn==21.11.1
Automat==20.2.0
black==21.7b0
certifi==2021.10.8
cffi==1.15.0
channels==3.0.4
channels-redis==3.3.0
charset-normalizer==2.0.8
click==8.0.3
constantly==15.1.0
coreapi==2.3.3
coreschema==0.0.4
cryptography==36.0.0
daphne==3.0.2
Django==3.2.6
django-cors-headers==3.8.0
django-stubs==1.9.0
django-stubs-ext==0.3.1
djangorestframework==3.12.4
djangorestframework-stubs==1.4.0
dodgy==0.2.1
flake8==3.9.2
flake8-polyfill==1.0.2
hiredis==2.0.0
hyperlink==21.0.0
idna==3.3
incremental==21.3.0
iniconfig==1.1.1
isort==5.10.1
itypes==1.2.0
Jinja2==3.0.3
lazy-object-proxy==1.6.0
MarkupSafe==2.0.1
mccabe==0.6.1
msgpack==1.0.3
mypy==0.910
mypy-extensions==0.4.3
packaging==21.3
pathspec==0.9.0
pep8-naming==0.10.0
platformdirs==2.4.0
pluggy==0.13.1
prospector==1.5.1
psycopg2-binary==2.9.1
py==1.11.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycodestyle==2.7.0
pycparser==2.21
pydocstyle==6.1.1
pyflakes==2.3.1
pylint==2.12.1
pylint-celery==0.3
pylint-django==2.4.4
pylint-flask==0.6
pylint-plugin-utils==0.6
pyOpenSSL==21.0.0
pyparsing==3.0.6
pytest==6.2.4
pytest-django==4.4.0
pytest-env==0.6.2
pytz==2021.3
PyYAML==6.0
regex==2021.11.10
requests==2.26.0
requirements-detector==0.7
rope==0.19.0
selenium==3.141.0
service-identity==21.1.0
setoptconf-tmp==0.3.1
six==1.16.0
snowballstemmer==2.2.0
sqlparse==0.4.2
toml==0.10.2
tomli==1.2.2
Twisted==21.7.0
txaio==21.2.1
types-pytz==2021.3.1
types-PyYAML==6.0.1
types-selenium==3.141.3
typing_extensions==4.0.0
uritemplate==4.1.1
urllib3==1.26.7
wrapt==1.13.3
zope.interface==5.4.0

@JinLisek JinLisek added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 28, 2021
@JinLisek JinLisek changed the title >= not supported between instances of NoneType and tuple when using new version of pylint >= not supported between instances of NoneType and tuple when using 2.12.1 version Nov 28, 2021
@Pierre-Sassoulas
Copy link
Member

Hey, thank you for the very detailed issue. Prospector is using pylint's internal and they changed recentely, it's going to be handled in prospector itself here.

@Pierre-Sassoulas Pierre-Sassoulas added Downstream Bug 🪲 The problem happens in a lib depending on pylint, not pylint and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 28, 2021
@Pierre-Sassoulas
Copy link
Member

Just a small thing, pictures can't be searched by crawler bot so it's harder to find the issue if you use them. Also they can't be read by visually impaired person so please copy paste the text content if possible :)

@JinLisek
Copy link
Author

Thanks @Pierre-Sassoulas, I was looking in the wrong place then. :) I'm closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Downstream Bug 🪲 The problem happens in a lib depending on pylint, not pylint
Projects
None yet
Development

No branches or pull requests

2 participants