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

Crash 'FunctionDef' object has no attribute 'ancestors' #5646

Closed
doctoryes opened this issue Jan 7, 2022 · 3 comments · Fixed by #5652
Closed

Crash 'FunctionDef' object has no attribute 'ancestors' #5646

doctoryes opened this issue Jan 7, 2022 · 3 comments · Fixed by #5652
Assignees
Labels
Crash 💥 A bug that makes pylint crash
Milestone

Comments

@doctoryes
Copy link

Bug description

When parsing the file here:

https://github.com/openedx/XBlock/blob/59c2f28e32548b8cb78b8f7c733bf64689a9a751/xblock/test/test_core.py

pylint crashed with a AttributeError and with the following stacktrace:

Traceback (most recent call last):
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1034, in _check_files
    self._check_file(get_ast, check_astroid_module, file)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1069, in _check_file
    check_astroid_module(ast_node)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1203, in check_astroid_module
    retval = self._check_astroid_module(
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1250, in _check_astroid_module
    walker.walk(node)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/checkers/refactoring/implicit_booleaness_checker.py", line 142, in visit_compare
    self._check_use_implicit_booleaness_not_comparison(node)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/checkers/refactoring/implicit_booleaness_checker.py", line 167, in _check_use_implicit_booleaness_not_comparison
    mother_classes = self.base_classes_of_node(target_instance)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/checkers/refactoring/implicit_booleaness_checker.py", line 214, in base_classes_of_node
    return [instance.name] + [x.name for x in instance.ancestors()]
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/astroid/bases.py", line 134, in __getattr__
    return getattr(self._proxied, name)
AttributeError: 'FunctionDef' object has no attribute 'ancestors'

Configuration

No response

Command used

`pylint xblock` was the command used.

The project uses Tox, so that command was indirectly run by running `tox -e quality` from the top-level dir of the https://github.com/openedx/XBlock repository.

Pylint output

************* Module xblock.test.test_plugin
xblock/test/test_plugin.py:68:11: C1803: 'list(...) == []' can be simplified to 'not list(...)' as an empty sequence is falsey (use-implicit-booleaness-not-comparison)
Exception on node <Compare l.747 at 0x114d6d7c0> in file '/Users/jeskew/edx/src/XBlock/xblock/test/test_core.py'
Traceback (most recent call last):
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/checkers/refactoring/implicit_booleaness_checker.py", line 142, in visit_compare
    self._check_use_implicit_booleaness_not_comparison(node)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/checkers/refactoring/implicit_booleaness_checker.py", line 167, in _check_use_implicit_booleaness_not_comparison
    mother_classes = self.base_classes_of_node(target_instance)
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/pylint/checkers/refactoring/implicit_booleaness_checker.py", line 214, in base_classes_of_node
    return [instance.name] + [x.name for x in instance.ancestors()]
  File "/Users/jeskew/edx/src/XBlock/.tox/quality/lib/python3.8/site-packages/astroid/bases.py", line 134, in __getattr__
    return getattr(self._proxied, name)
AttributeError: 'FunctionDef' object has no attribute 'ancestors'
************* Module xblock.test.test_core
xblock/test/test_core.py:1:0: F0001: Fatal error while checking 'xblock/test/test_core.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/Users/jeskew/Library/Caches/pylint/pylint-crash-2022-01-07-16.txt'. (fatal)

Expected behavior

All the repo code should pass pylint checks. In fact, if pylint is pinned back to pylint<2.12, all the repo code does pass pylint checks.

Pylint version

pylint 2.12.2
astroid 2.9.2
Python 3.8.7 (default, Feb  1 2021, 15:53:07)
[Clang 11.0.3 (clang-1103.0.32.62)]

OS / Environment

macOS Catalina, version 10.15.7
Using iTerm2 terminal

Additional dependencies

#
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
#
#    make upgrade
#
appdirs==1.4.4
    # via
    #   -r requirements/django.txt
    #   fs
astroid==2.9.2
    # via
    #   -r requirements/test.in
    #   pylint
    #   pylint-celery
attrs==21.4.0
    # via
    #   hypothesis
    #   pytest
boto3==1.20.30
    # via
    #   -r requirements/django.txt
    #   fs-s3fs
botocore==1.23.30
    # via
    #   -r requirements/django.txt
    #   boto3
    #   s3transfer
click==8.0.3
    # via
    #   click-log
    #   code-annotations
    #   edx-lint
click-log==0.3.2
    # via edx-lint
code-annotations==1.2.0
    # via edx-lint
coverage[toml]==6.2
    # via
    #   -r requirements/test.in
    #   pytest-cov
ddt==1.4.4
    # via -r requirements/test.in
diff-cover==4.0.0
    # via
    #   -c requirements/constraints.txt
    #   -r requirements/test.in
distlib==0.3.4
    # via virtualenv
    # via
    #   -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
    #   -r requirements/django.txt
    #   django-pyfs
django-pyfs==3.1.0
    # via -r requirements/django.txt
edx-lint==5.2.1
    # via -r requirements/test.in
filelock==3.4.2
    # via
    #   tox
    #   virtualenv
fs==2.4.14
    # via
    #   -r requirements/django.txt
    #   django-pyfs
    #   fs-s3fs
fs-s3fs==1.1.1
    # via
    #   -r requirements/django.txt
    #   django-pyfs
hypothesis==6.34.2
    # via -r requirements/test.in
inflect==5.3.0
    # via jinja2-pluralize
iniconfig==1.1.1
    # via pytest
isort==5.10.1
    # via pylint
jinja2==3.0.3
    # via
    #   code-annotations
    #   diff-cover
    #   jinja2-pluralize
jinja2-pluralize==0.3.0
    # via diff-cover
jmespath==0.10.0
    # via
    #   -r requirements/django.txt
    #   boto3
    #   botocore
lazy==1.4
    # via -r requirements/django.txt
lazy-object-proxy==1.7.1
    # via astroid
lxml==4.7.1
    # via -r requirements/django.txt
markupsafe==2.0.1
    # via
    #   -r requirements/django.txt
    #   jinja2
mccabe==0.6.1
    # via pylint
mock==4.0.3
    # via -r requirements/test.in
packaging==21.3
    # via
    #   pytest
    #   tox
path==16.2.0
    # via -r requirements/test.in
pbr==5.8.0
    # via stevedore
platformdirs==2.4.1
    # via
    #   pylint
    #   virtualenv
pluggy==1.0.0
    # via
    #   diff-cover
    #   pytest
    #   tox
py==1.11.0
    # via
    #   pytest
    #   tox
pycodestyle==2.8.0
    # via -r requirements/test.in
pygments==2.11.2
    # via diff-cover
pylint==2.12.2
    # via
    #   -r requirements/test.in
    #   edx-lint
    #   pylint-celery
    #   pylint-django
    #   pylint-plugin-utils
pylint-celery==0.3
    # via edx-lint
pylint-django==2.5.0
    # via edx-lint
pylint-plugin-utils==0.7
    # via
    #   pylint-celery
    #   pylint-django
pyparsing==3.0.6
    # via packaging
pytest==6.2.5
    # via
    #   -r requirements/test.in
    #   pytest-cov
    #   pytest-django
pytest-cov==3.0.0
    # via -r requirements/test.in
pytest-django==4.5.2
    # via -r requirements/test.in
python-dateutil==2.8.2
    # via
    #   -r requirements/django.txt
    #   botocore
python-slugify==5.0.2
    # via code-annotations
pytz==2021.3
    # via
    #   -r requirements/django.txt
    #   django
    #   fs
pyyaml==6.0
    # via
    #   -r requirements/django.txt
    #   code-annotations
s3transfer==0.5.0
    # via
    #   -r requirements/django.txt
    #   boto3
simplejson==3.17.6
    # via -r requirements/django.txt
six==1.16.0
    # via
    #   -r requirements/django.txt
    #   edx-lint
    #   fs
    #   fs-s3fs
    #   python-dateutil
    #   tox
    #   virtualenv
sortedcontainers==2.4.0
    # via hypothesis
sqlparse==0.4.2
    # via
    #   -r requirements/django.txt
    #   django
stevedore==3.5.0
    # via code-annotations
text-unidecode==1.3
    # via python-slugify
toml==0.10.2
    # via
    #   pylint
    #   pytest
    #   tox
tomli==2.0.0
    # via coverage
tox==3.24.5
    # via -r requirements/test.in
typing-extensions==4.0.1
    # via
    #   astroid
    #   pylint
urllib3==1.26.7
    # via
    #   -r requirements/django.txt
    #   botocore
virtualenv==20.13.0
    # via tox
web-fragments==2.0.0
    # via -r requirements/django.txt
webob==1.8.7
    # via -r requirements/django.txt
wrapt==1.13.3
    # via astroid

# The following packages are considered to be unsafe in a requirements file:
# setuptools
@doctoryes doctoryes added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 7, 2022
doctoryes pushed a commit to doctoryes/pylint that referenced this issue Jan 7, 2022
pylint-dev#5646

Handle when the 'ancestors' attribute is not present in an object.
doctoryes pushed a commit to doctoryes/pylint that referenced this issue Jan 7, 2022
pylint-dev#5646

Handle when the 'ancestors' attribute is not present in an object.
@doctoryes
Copy link
Author

A possible fix is here:
#5647

@doctoryes
Copy link
Author

doctoryes commented Jan 7, 2022

I saw this crash bug with this version of the XBlock repo code:
https://github.com/openedx/XBlock/tree/b67123d3597e8dd1cca4efdda3d7d7415bc3ceeb
...except that the pylint requirements were updated as specified above.

I'm including this specific URL as I'm about to commit some changes which fix the pylint errors causing the crash.

@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 7, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Jan 7, 2022
@DanielNoord
Copy link
Collaborator

Reproducible code is:

class ParentWithProperty:
    def _parent_function(cls):
        return {}


class MyClassWithProxy(ParentWithProperty):
    @property
    def _my_property(cls):
        return {}


def func():
    xblock = MyClassWithProxy()
    assert xblock._parent_function == {}
    assert xblock._services_requested == {}

Assigning myself, probably get to this next week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash
Projects
None yet
3 participants