Skip to content

Commit 0007bc9

Browse files
arthaudmeta-codesync[bot]
authored andcommitted
Add test demonstrating unresolved calls with class stubs
Summary: We fail to resolve `super().__init__()` calls when the parent class is defined as `class A: ...`. The call graph building has 2 different paths: Using go-to-definition: this returns None (since A is empty) Using type resolution: `super().__init__` returns a `BoundMethod[Self@B, …]`. We don’t currently handle the Self type when resolving BoundMethods. Even if we did, we would resolve to `B.__init__` instead of `A.__init__` or `object.__init__`. Reviewed By: tianhan0 Differential Revision: D91778720 fbshipit-source-id: 4c63d4fecaa3e3a72daa501a1fc9739a60d8459f
1 parent f7620c3 commit 0007bc9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

pyrefly/lib/test/pysa/call_graph.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7004,3 +7004,43 @@ def foo(x: PropertyCallable, y: PropertyCallableReturn):
70047004
)]
70057005
}
70067006
);
7007+
7008+
// From the pysa integration test: constructors.py
7009+
call_graph_testcase!(
7010+
test_stub_parent_class,
7011+
TEST_MODULE_NAME,
7012+
r#"
7013+
class A:
7014+
...
7015+
7016+
class B(A):
7017+
def __init__(self, a, b) -> None:
7018+
super().__init__(a, b)
7019+
"#,
7020+
&|context: &ModuleContext| {
7021+
vec![(
7022+
"test.B.__init__",
7023+
vec![
7024+
(
7025+
"7:5-7:12",
7026+
constructor_call_callees(
7027+
vec![
7028+
create_call_target("builtins.super.__init__", TargetType::Function)
7029+
.with_implicit_receiver(ImplicitReceiver::TrueWithObjectReceiver)
7030+
.with_receiver_class_for_test("builtins.super", context),
7031+
],
7032+
vec![
7033+
create_call_target("builtins.object.__new__", TargetType::Function)
7034+
.with_is_static_method(true),
7035+
],
7036+
),
7037+
),
7038+
(
7039+
"7:5-7:27",
7040+
// TODO(T253219415): Resolve `__init__` call.
7041+
unresolved_expression_callees(UnresolvedReason::UnexpectedDefiningClass),
7042+
),
7043+
],
7044+
)]
7045+
}
7046+
);

0 commit comments

Comments
 (0)