Skip to content

Crash on combination of decorators and properties #5382

@DanielNoord

Description

@DanielNoord

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crash 💥A bug that makes pylint crash

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions