PY-44858 Create regular packages in refactorings initiated from top-level files in source/content roots

Otherwise, if someone wants to move a definition/extract a superclass from there to
a brand-new package, e.g. from main.py to pkg/mod.py, a namespace "pkg" package will
be created.

Restore the original behavior of PyExtractSuperclassTest.testMultifileNew: the origin
file was inside a regular project root without __init__.py alongside.

GitOrigin-RevId: 750414b18582740076c14bfcfd07fa38992b4428
This commit is contained in:
Mikhail Golubev
2024-07-24 16:18:40 +00:00
committed by intellij-monorepo-bot
parent 1c026ac470
commit f392777e01
7 changed files with 11 additions and 0 deletions
@@ -41,6 +41,7 @@ fun isNamespacePackage(element: PsiElement): Boolean {
fun isInNamespacePackage(element: PsiElement): Boolean {
val myFile = element.containingFile ?: return false
val parentDirectory = myFile.containingDirectory
if (parentDirectory.virtualFile in PyUtil.getSourceRoots(element)) return false
return parentDirectory != null && isNamespacePackage(parentDirectory)
}
@@ -427,6 +427,12 @@ public class PyMoveTest extends PyTestCase {
});
}
public void testMoveSymbolFromTopLevelModuleToNewPackageCreatesInitPy() {
doComparingDirectories(testDir -> {
moveSymbols(testDir, "pkg/subpkg/b.py", "MyClass");
});
}
//PY-44858
public void testMoveNotCreateInitPyForNamespacePackagesToAnotherDirectory() {
doMoveSymbolsTest("pkg/subpkg/B/module_b.py", "myfunc");