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-2.5.0 cannot parse a class overriding JSONEncoder's default method #3527

Closed
ppentchev opened this issue Apr 27, 2020 · 1 comment
Closed

Comments

@ppentchev
Copy link

ppentchev commented Apr 27, 2020

Hi,

Thanks a lot for all your work on pylint and the related projects!

There have been previous issues raised about pylint's handling of classes that inherit from json.JSONEncoder and override its .default() method, mostly because JSONEncoder is woefully special in having a "default" propertyfor its constructor and then doing something crazy with it. However, at least the previously-reported issues I could find (e.g. #414) are kind of solved by disabling the method-hidden diagnostics for the default() method.

Now it seems that pylint-2.5.0 cannot even parse such a class.

Steps to reproduce

  1. Download storpool-5.3.1 from PyPI (https://pypi.org/project/storpool/5.3.1/#files)
  2. Run python3 -m tox -e python_lint_3 and watch it break
  3. Change the "pylint" dependency to "pylint != 2.5.0", watch the test pass with pylint-2.4.4.

For the record, yes, I know that we are doing some pretty horrible things in the JsonObjectImpl class, and we are in the process of redesigning the StorPool Python bindings in a much saner way, but the current version seems to work with pylint-2.4.4.

I am sorry that I could not provide a smaller testcase, but a couple of attempts at simplfiying this failed - pylint did not break on the much simpler versions. I could try harder to provide a simpler test case if it will make your task easier.

Current behavior

python_lint_3 run-test: commands[0] | pylint --disable=R0205,R1717,R1718 --ignore=spapi.py,sptype.py,sptypes.py,sputils.py storpool unit_tests
Traceback (most recent call last):
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/lint/run.py", line 338, in __init__
    linter.check(args)
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 870, in check
    self._check_files(
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 904, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 930, in _check_file
    check_astroid_module(ast_node)
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1062, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1107, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/home/roam/tmp/v/roam/sphmf/storpool-5.3.1/.tox/python_lint_3/lib/python3.8/site-packages/pylint/checkers/classes.py", line 996, in visit_functiondef
    for subklass in mro[1 : mro.index(overridden_frame) + 1]:
ValueError: <ClassDef.JSONEncoder l.73 at 0x7f43043eed30> is not in list

Expected behavior

Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

pylint --version output

astroid 2.4.0
Python 3.8.2 (default, Apr  1 2020, 15:52:55) 
[GCC 9.3.0]

Thanks in advance for your time, and keep up the great work!

G'luck,
Peter

PCManticore added a commit that referenced this issue Apr 28, 2020
The patch replaces `mro()` with `ancestors()` as the former is not
fully capable of generating the complete linearization when
dealing with ambiguous inferences.

Close #3527
PCManticore added a commit that referenced this issue Apr 28, 2020
The patch replaces `mro()` with `ancestors()` as the former is not
fully capable of generating the complete linearization when
dealing with ambiguous inferences.

Close #3527
@PCManticore
Copy link
Contributor

Handled by #3532. Thank you for the report! We'll release 2.5.1 in the following days with the most urgent patches.

PCManticore added a commit that referenced this issue Apr 28, 2020
The patch replaces `mro()` with `ancestors()` as the former is not
fully capable of generating the complete linearization when
dealing with ambiguous inferences.

Close #3527
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

2 participants