@@ -15112,6 +15112,93 @@ TEST(pipeline_python_decorated_nested_class_extracted_parallel) {
1511215112 return pyn_run_decorated_nested(52);
1511315113}
1511415114
15115+ /* A class nested in a class is walked by the Python LSP under its outer
15116+ * class (m.Outer.Inner): a typed-parameter call, a self call and a
15117+ * constructor call in its methods resolve, and so does a decorated nested
15118+ * class. Walked under the module (m.Inner) none of the LSP rows joined the
15119+ * method nodes, so the calls fell to name guesses or got no edge. */
15120+ static const char pyn_nested_class_py[] = "class Helper:\n"
15121+ " def go(self):\n"
15122+ " return 1\n"
15123+ "\n"
15124+ "def deco(cls):\n"
15125+ " return cls\n"
15126+ "\n"
15127+ "class Outer:\n"
15128+ " class Inner:\n"
15129+ " def run(self, h: Helper):\n"
15130+ " return h.go()\n"
15131+ "\n"
15132+ " def again(self):\n"
15133+ " return self.run(Helper())\n"
15134+ "\n"
15135+ " @deco\n"
15136+ " class Decorated:\n"
15137+ " def run(self, h: Helper):\n"
15138+ " return h.go()\n";
15139+
15140+ static int pyn_run_nested_class(int fillers) {
15141+ char tmp[256];
15142+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_py_nestcls_XXXXXX");
15143+ if (!cbm_mkdtemp(tmp)) {
15144+ FAIL("tmpdir");
15145+ }
15146+ write_temp_file(tmp, "sn.py", pyn_nested_class_py);
15147+ for (int i = 0; i < fillers; i++) {
15148+ char name[64];
15149+ char body[128];
15150+ snprintf(name, sizeof(name), "filler%d.py", i);
15151+ snprintf(body, sizeof(body), "def filler%d():\n return %d\n", i, i);
15152+ write_temp_file(tmp, name, body);
15153+ }
15154+ char *old_workers = getenv("CBM_WORKERS");
15155+ char *saved = old_workers ? strdup(old_workers) : NULL;
15156+ if (fillers > 0) {
15157+ cbm_setenv("CBM_WORKERS", "4", 1);
15158+ }
15159+ char db_path[512];
15160+ snprintf(db_path, sizeof(db_path), "%s/nestcls.db", tmp);
15161+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
15162+ int rc = p ? cbm_pipeline_run(p) : -1;
15163+ cbm_store_t *s = rc == 0 ? cbm_store_open_path(db_path) : NULL;
15164+ const char *project = p ? cbm_pipeline_project_name(p) : NULL;
15165+ bool typed = s && pyn_edge_with(s, project, "sn.Outer.Inner.run", "sn.Helper.go", "CALLS",
15166+ "\"strategy\":\"lsp_");
15167+ bool self_call = s && pyn_edge_with(s, project, "sn.Outer.Inner.again", "sn.Outer.Inner.run",
15168+ "CALLS", "\"strategy\":\"lsp_");
15169+ bool ctor = s && pyn_edge_with(s, project, "sn.Outer.Inner.again", "sn.Helper", "CALLS",
15170+ "\"strategy\":\"lsp_");
15171+ bool decorated = s && pyn_edge_with(s, project, "sn.Outer.Decorated.run", "sn.Helper.go",
15172+ "CALLS", "\"strategy\":\"lsp_");
15173+ if (s) {
15174+ cbm_store_close(s);
15175+ }
15176+ if (p) {
15177+ cbm_pipeline_free(p);
15178+ }
15179+ if (saved) {
15180+ cbm_setenv("CBM_WORKERS", saved, 1);
15181+ free(saved);
15182+ } else {
15183+ cbm_unsetenv("CBM_WORKERS");
15184+ }
15185+ th_rmtree(tmp);
15186+ ASSERT_EQ(rc, 0);
15187+ ASSERT_TRUE(typed);
15188+ ASSERT_TRUE(self_call);
15189+ ASSERT_TRUE(ctor);
15190+ ASSERT_TRUE(decorated);
15191+ PASS();
15192+ }
15193+
15194+ TEST(pipeline_python_nested_class_methods_resolve) {
15195+ return pyn_run_nested_class(0);
15196+ }
15197+
15198+ TEST(pipeline_python_nested_class_methods_resolve_parallel) {
15199+ return pyn_run_nested_class(52);
15200+ }
15201+
1511515202TEST(pipeline_python_project) {
1511615203 /* Port of TestPipelinePythonProject */
1511715204 const char *files[] = {"main.py", "utils.py"};
@@ -24621,6 +24708,8 @@ SUITE(pipeline) {
2462124708 RUN_TEST(pipeline_python_nested_helper_keeps_tests_parallel_issue1548);
2462224709 RUN_TEST(pipeline_python_decorated_nested_class_extracted);
2462324710 RUN_TEST(pipeline_python_decorated_nested_class_extracted_parallel);
24711+ RUN_TEST(pipeline_python_nested_class_methods_resolve);
24712+ RUN_TEST(pipeline_python_nested_class_methods_resolve_parallel);
2462424713 RUN_TEST(pipeline_header_include_target_is_independent_of_registration_order);
2462524714 RUN_TEST(pipeline_imports_multi_symbol_edges);
2462624715 RUN_TEST(pipeline_go_cross_package_call);
0 commit comments