@@ -16209,6 +16209,93 @@ TEST(pipeline_python_decorated_nested_class_extracted_parallel) {
1620916209 return pyn_run_decorated_nested(52);
1621016210}
1621116211
16212+ /* A class nested in a class is walked by the Python LSP under its outer
16213+ * class (m.Outer.Inner): a typed-parameter call, a self call and a
16214+ * constructor call in its methods resolve, and so does a decorated nested
16215+ * class. Walked under the module (m.Inner) none of the LSP rows joined the
16216+ * method nodes, so the calls fell to name guesses or got no edge. */
16217+ static const char pyn_nested_class_py[] = "class Helper:\n"
16218+ " def go(self):\n"
16219+ " return 1\n"
16220+ "\n"
16221+ "def deco(cls):\n"
16222+ " return cls\n"
16223+ "\n"
16224+ "class Outer:\n"
16225+ " class Inner:\n"
16226+ " def run(self, h: Helper):\n"
16227+ " return h.go()\n"
16228+ "\n"
16229+ " def again(self):\n"
16230+ " return self.run(Helper())\n"
16231+ "\n"
16232+ " @deco\n"
16233+ " class Decorated:\n"
16234+ " def run(self, h: Helper):\n"
16235+ " return h.go()\n";
16236+
16237+ static int pyn_run_nested_class(int fillers) {
16238+ char tmp[256];
16239+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_py_nestcls_XXXXXX");
16240+ if (!cbm_mkdtemp(tmp)) {
16241+ FAIL("tmpdir");
16242+ }
16243+ write_temp_file(tmp, "sn.py", pyn_nested_class_py);
16244+ for (int i = 0; i < fillers; i++) {
16245+ char name[64];
16246+ char body[128];
16247+ snprintf(name, sizeof(name), "filler%d.py", i);
16248+ snprintf(body, sizeof(body), "def filler%d():\n return %d\n", i, i);
16249+ write_temp_file(tmp, name, body);
16250+ }
16251+ char *old_workers = getenv("CBM_WORKERS");
16252+ char *saved = old_workers ? strdup(old_workers) : NULL;
16253+ if (fillers > 0) {
16254+ cbm_setenv("CBM_WORKERS", "4", 1);
16255+ }
16256+ char db_path[512];
16257+ snprintf(db_path, sizeof(db_path), "%s/nestcls.db", tmp);
16258+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
16259+ int rc = p ? cbm_pipeline_run(p) : -1;
16260+ cbm_store_t *s = rc == 0 ? cbm_store_open_path(db_path) : NULL;
16261+ const char *project = p ? cbm_pipeline_project_name(p) : NULL;
16262+ bool typed = s && pyn_edge_with(s, project, "sn.Outer.Inner.run", "sn.Helper.go", "CALLS",
16263+ "\"strategy\":\"lsp_");
16264+ bool self_call = s && pyn_edge_with(s, project, "sn.Outer.Inner.again", "sn.Outer.Inner.run",
16265+ "CALLS", "\"strategy\":\"lsp_");
16266+ bool ctor = s && pyn_edge_with(s, project, "sn.Outer.Inner.again", "sn.Helper", "CALLS",
16267+ "\"strategy\":\"lsp_");
16268+ bool decorated = s && pyn_edge_with(s, project, "sn.Outer.Decorated.run", "sn.Helper.go",
16269+ "CALLS", "\"strategy\":\"lsp_");
16270+ if (s) {
16271+ cbm_store_close(s);
16272+ }
16273+ if (p) {
16274+ cbm_pipeline_free(p);
16275+ }
16276+ if (saved) {
16277+ cbm_setenv("CBM_WORKERS", saved, 1);
16278+ free(saved);
16279+ } else {
16280+ cbm_unsetenv("CBM_WORKERS");
16281+ }
16282+ th_rmtree(tmp);
16283+ ASSERT_EQ(rc, 0);
16284+ ASSERT_TRUE(typed);
16285+ ASSERT_TRUE(self_call);
16286+ ASSERT_TRUE(ctor);
16287+ ASSERT_TRUE(decorated);
16288+ PASS();
16289+ }
16290+
16291+ TEST(pipeline_python_nested_class_methods_resolve) {
16292+ return pyn_run_nested_class(0);
16293+ }
16294+
16295+ TEST(pipeline_python_nested_class_methods_resolve_parallel) {
16296+ return pyn_run_nested_class(52);
16297+ }
16298+
1621216299TEST(pipeline_python_project) {
1621316300 /* Port of TestPipelinePythonProject */
1621416301 const char *files[] = {"main.py", "utils.py"};
@@ -25738,6 +25825,8 @@ SUITE(pipeline) {
2573825825 RUN_TEST(pipeline_python_nested_helper_keeps_tests_parallel_issue1548);
2573925826 RUN_TEST(pipeline_python_decorated_nested_class_extracted);
2574025827 RUN_TEST(pipeline_python_decorated_nested_class_extracted_parallel);
25828+ RUN_TEST(pipeline_python_nested_class_methods_resolve);
25829+ RUN_TEST(pipeline_python_nested_class_methods_resolve_parallel);
2574125830 RUN_TEST(pipeline_header_include_target_is_independent_of_registration_order);
2574225831 RUN_TEST(pipeline_imports_multi_symbol_edges);
2574325832 RUN_TEST(pipeline_go_cross_package_call);
0 commit comments