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' #9543

Closed
carygravel opened this issue Apr 8, 2024 · 3 comments
Closed

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

carygravel opened this issue Apr 8, 2024 · 3 comments
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@carygravel
Copy link

Bug description

When parsing the following file:

<!--
 If sharing the code is not an option, please state so,
 but providing only the stacktrace would still be helpful.
 -->


"Scan dialog"

from gi.repository import GObject

class Scan():
    "Scan dialog"

    _device_list = []

    @GObject.Property(
        type=object, nick="Device list", blurb="Array of hashes of available devices"
    )
    def device_list(self):
        "getter for device_list attribute"
        return self._device_list

    @device_list.setter
    def device_list(self, newval):
        self._device_list = newval

    def set_device(self, device):
        "set the active device"
        if len(self.device_list):
            pass



pylint crashed with a ``AttributeError`` and with the following stacktrace:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pylint/lint/pylinter.py", line 1034, in _check_files
self._check_file(get_ast, check_astroid_module, file)
File "/usr/lib/python3/dist-packages/pylint/lint/pylinter.py", line 1069, in _check_file
check_astroid_module(ast_node)
File "/usr/lib/python3/dist-packages/pylint/lint/pylinter.py", line 1203, in check_astroid_module
retval = self._check_astroid_module(
File "/usr/lib/python3/dist-packages/pylint/lint/pylinter.py", line 1250, in _check_astroid_module
walker.walk(node)
File "/usr/lib/python3/dist-packages/pylint/utils/ast_walker.py", line 75, in walk
self.walk(child)
File "/usr/lib/python3/dist-packages/pylint/utils/ast_walker.py", line 75, in walk
self.walk(child)
File "/usr/lib/python3/dist-packages/pylint/utils/ast_walker.py", line 75, in walk
self.walk(child)
[Previous line repeated 1 more time]
File "/usr/lib/python3/dist-packages/pylint/utils/ast_walker.py", line 72, in walk
callback(astroid)
File "/usr/lib/python3/dist-packages/pylint/checkers/refactoring/implicit_booleaness_checker.py", line 110, in visit_call
mother_classes = self.base_classes_of_node(instance)
File "/usr/lib/python3/dist-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 "/usr/lib/python3/dist-packages/astroid/bases.py", line 134, in getattr
return getattr(self._proxied, name)
File "/usr/lib/python3/dist-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 bug.py

Pylint output

Exception on node <Call l.23 at 0x7fa058782fb0> in file 'bug.py'
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/usr/lib/python3/dist-packages/pylint/checkers/refactoring/implicit_booleaness_checker.py", line 110, in visit_call
    mother_classes = self.base_classes_of_node(instance)
  File "/usr/lib/python3/dist-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 "/usr/lib/python3/dist-packages/astroid/bases.py", line 134, in __getattr__
    return getattr(self._proxied, name)
  File "/usr/lib/python3/dist-packages/astroid/bases.py", line 134, in __getattr__
    return getattr(self._proxied, name)
AttributeError: 'FunctionDef' object has no attribute 'ancestors'

Expected behavior

I would expect no crash

Pylint version

pylint 2.12.2
astroid 2.9.3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]

OS / Environment

Linux Mint 21.3 Virginia
base: Ubuntu 22.04 jammy

Additional dependencies

cffi==1.16.0
charset-normalizer==3.3.2
coverage==7.3.2
cryptography==41.0.5
Deprecated==1.2.14
deprecation==2.1.0
exceptiongroup==1.2.0
img2pdf==0.5.1
iniconfig==2.0.0
lxml==4.9.3
markdown-it-py==3.0.0
mdurl==0.1.2
ocrmypdf==15.4.3
packaging==23.2
pdfminer.six==20221105
pikepdf==8.7.1
Pillow==10.1.0
pluggy==1.3.0
pycairo==1.25.1
pycparser==2.21
Pygments==2.17.2
PyGObject==3.46.0
pytest==7.4.3
pytest-cov==4.1.0
pytest-timeout==2.2.0
pytest-xvfb==3.0.0
python-sane==2.9.1
PyVirtualDisplay==3.0
reportlab==4.0.7
rich==13.7.0
tesserocr==2.6.2
tomli==2.0.1
wrapt==1.16.0
@carygravel carygravel added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 8, 2024
@jacobtylerwalls
Copy link
Member

Feel free to reopen if you can reproduce on a recent version of pylint.

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
@jacobtylerwalls
Copy link
Member

Likely duplicate of #5646

@jacobtylerwalls jacobtylerwalls added Duplicate 🐫 Duplicate of an already existing issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 9, 2024
@carygravel
Copy link
Author

Apologies for the noise. Confirmed fixed in v3.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants