Skip to content

Validator.method_source returns "" for property and cached_property #551

@anmyachev

Description

@anmyachev

An interesting detail is that source_file_def_line method takes into account these types of objects and correctly finds the source code of the functions wrapped in these properties.

def source_file_def_line(self):
"""
Number of line where the object is defined in its file.
"""
try:
if isinstance(self.code_obj, property):
sourcelines = self._getsourcelines(self.code_obj.fget)
elif isinstance(self.code_obj, functools.cached_property):
sourcelines = self._getsourcelines(self.code_obj.func)
else:
sourcelines = self._getsourcelines(self.code_obj)
# getsourcelines will return the line of the first decorator found for the

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions