Raw calls for attribute reads that may run a `@property` getter. `response.text` names no call, but reading it runs `Response.text` when that is a property. Only reads whose receiver is typed the way a member call would be are recorded: `self.a` (minus the fields the class assigns,
(
function_bodies, source: bytes, str_path: str,
var_types: dict[str, dict[str, str | None]],
attr_types: dict[str, dict[str, str | None]],
method_owner: dict[str, str],
)
| 4046 | |
| 4047 | |
| 4048 | def _python_property_reads( |
| 4049 | function_bodies, source: bytes, str_path: str, |
| 4050 | var_types: dict[str, dict[str, str | None]], |
| 4051 | attr_types: dict[str, dict[str, str | None]], |
| 4052 | method_owner: dict[str, str], |
| 4053 | ) -> list[dict]: |
| 4054 | """Raw calls for attribute reads that may run a `@property` getter. |
| 4055 | |
| 4056 | `response.text` names no call, but reading it runs `Response.text` when that |
| 4057 | is a property. Only reads whose receiver is typed the way a member call |
| 4058 | would be are recorded: `self.a` (minus the fields the class assigns, |
| 4059 | `self.a = ...`), a typed local or parameter (`receiver_type`), and |
| 4060 | `self.X.a` with `X` bound to one class (`_python_self_attr_type`). The |
| 4061 | resolver binds them like member calls and keeps only targets marked |
| 4062 | `_py_property`, as a `references` edge, so a plain field or a method reference gets no edge. |
| 4063 | """ |
| 4064 | out: list[dict] = [] |
| 4065 | for caller_nid, body in function_bodies: |
| 4066 | owner = method_owner.get(caller_nid, "") |
| 4067 | fields = attr_types.get(owner, {}) |
| 4068 | stack = list(getattr(body, "children", ())) |
| 4069 | while stack: |
| 4070 | node = stack.pop() |
| 4071 | if node.type in ("function_definition", "class_definition", "lambda"): |
| 4072 | continue |
| 4073 | stack.extend(node.children) |
| 4074 | if node.type != "attribute": |
| 4075 | continue |
| 4076 | parent = node.parent |
| 4077 | if parent is not None and parent.type == "call" and _same_node(parent.child_by_field_name("function"), node): |
| 4078 | continue # a method call: the call walk owns it |
| 4079 | if _python_attribute_is_store(node): |
| 4080 | continue |
| 4081 | obj, attr_n = node.child_by_field_name("object"), node.child_by_field_name("attribute") |
| 4082 | if obj is None or attr_n is None: |
| 4083 | continue |
| 4084 | attr = _read_text(attr_n, source) |
| 4085 | typed: dict = {} |
| 4086 | if obj.type == "identifier": |
| 4087 | name = _read_text(obj, source) |
| 4088 | if name == "self": |
| 4089 | if owner and attr not in fields: |
| 4090 | typed = {"receiver": "self"} |
| 4091 | else: |
| 4092 | cls = var_types.get(caller_nid, {}).get(name) |
| 4093 | if cls: |
| 4094 | typed = {"receiver": name, "receiver_type": cls} |
| 4095 | else: |
| 4096 | self_attr = _python_self_attr(obj, source) |
| 4097 | cls = fields.get(self_attr) if self_attr else None |
| 4098 | if cls: |
| 4099 | typed = {"receiver": f"self.{self_attr}", "_python_self_attr_type": cls} |
| 4100 | if typed: |
| 4101 | out.append({ |
| 4102 | "caller_nid": caller_nid, |
| 4103 | "callee": attr, |
| 4104 | "is_member_call": True, |
| 4105 | "source_file": str_path, |
no test coverage detected