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 on combination of decorators and properties #5382

Closed
DanielNoord opened this issue Nov 24, 2021 · 7 comments · Fixed by #5550
Closed

Crash on combination of decorators and properties #5382

DanielNoord opened this issue Nov 24, 2021 · 7 comments · Fixed by #5550
Labels
Crash 💥 A bug that makes pylint crash
Milestone

Comments

@DanielNoord
Copy link
Collaborator

DanielNoord commented Nov 24, 2021

Bug description

The following file should be added to our functional tests:

tests/functional/r/regression_02/regression_node_statement_two.py:

"""Test to see we don't crash on this code in pandas.
See: https://github.com/pandas-dev/pandas/blob/master/pandas/core/indexes/period.py
"""
# pylint: disable=no-member, redefined-builtin, invalid-name, missing-class-docstring


def my_decorator(*params):
    def decorator(decorated):
        return decorated

    return decorator


class ClassWithProperty:
    def f():
        return "string"

    f.__name__ = "name"
    f.__doc__ = "docstring"

    hour = property(f)


class ClassWithDecorator:
    @my_decorator(ClassWithProperty.hour.fget)
    def my_property(self) -> str:
        return "a string"

Found while working on #5310

Similar crash occurs on this file:
https://github.com/django/django/blob/main/django/template/response.py

Configuration

No response

Command used

pylint

Pylint output

Traceback (most recent call last):
  File "/Users/daniel/DocumentenLaptop/Programming/Github/pylint/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/Users/daniel/DocumentenLaptop/Programming/Github/pylint/pylint/checkers/typecheck.py", line 1041, in visit_attribute
    for n in owner.getattr(node.attrname)
  File "/Users/daniel/.pyenv/versions/3.10.0/envs/pylint-3.10.0/lib/python3.10/site-packages/astroid/nodes/scoped_nodes.py", line 1795, in getattr
    found_attrs.append(self.special_attributes.lookup(name))
  File "/Users/daniel/.pyenv/versions/3.10.0/envs/pylint-3.10.0/lib/python3.10/site-packages/astroid/interpreter/objectmodel.py", line 127, in lookup
    return getattr(self, IMPL_PREFIX + name)
  File "/Users/daniel/.pyenv/versions/3.10.0/envs/pylint-3.10.0/lib/python3.10/site-packages/astroid/interpreter/objectmodel.py", line 802, in attr_fget
    property_accessor.postinit(args=func.args, body=func.body)
AttributeError: 'Property' object has no attribute 'args'

Expected behavior

No crash

Pylint version

Latest commit on `main`.

OS / Environment

No response

Additional dependencies

No response

@DanielNoord DanielNoord added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling Crash 💥 A bug that makes pylint crash and removed Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 24, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.12.0 milestone Nov 24, 2021
@Pierre-Sassoulas
Copy link
Member

Blocker for 2.12, right ? :)

@DanielNoord
Copy link
Collaborator Author

Not necessarily if we postpone using statement(future=True) as well. I looked it into this but couldn't find a fix in 5 minutes so I had to give up for now.

Current code works fine (primer passes), crash only occurs on future behaviour.

@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.12.0, 2.13.0 Nov 24, 2021
@DanielNoord
Copy link
Collaborator Author

@Pierre-Sassoulas Could you test and see if you can reproduce this? I no longer can but I don't think I changed anything related to this crash.. 😅

@jacobtylerwalls
Copy link
Member

I actually tested this morning and couldn't reproduce either.

@DanielNoord
Copy link
Collaborator Author

Thanks @jacobtylerwalls! I'll close this then.

Obviously if anybody reports back that this is still an issue we can reopen.

@jacobtylerwalls
Copy link
Member

Do you want to add the test case?

@DanielNoord
Copy link
Collaborator Author

That's not a bad idea actually. I'll create a PR, thanks for the tip!

DanielNoord added a commit to DanielNoord/pylint that referenced this issue Dec 17, 2021
@DanielNoord DanielNoord linked a pull request Dec 17, 2021 that will close this issue
2 tasks
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
Development

Successfully merging a pull request may close this issue.

3 participants