diff --git a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibCanonicalPathProvider.kt b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibCanonicalPathProvider.kt
index bb83e6f43399..7c7f05f2463c 100644
--- a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibCanonicalPathProvider.kt
+++ b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibCanonicalPathProvider.kt
@@ -48,7 +48,8 @@ fun restoreStdlibCanonicalPath(qName: QualifiedName): QualifiedName? {
val head = components[0]
return when (head) {
- "_abcoll", "_collections", "_collections_abc" -> replace0("collections", components)
+ "_abcoll", "_collections" -> replace0("collections", components)
+ "_collections_abc" -> replace0("collections.abc", components)
"posix", "nt" -> replace0("os", components)
"_functools" -> replace0("functools", components)
diff --git a/python/testData/quickFixes/PyAddImportQuickFixTest/importAbstractContainersFromCollectionsABC/main.py b/python/testData/quickFixes/PyAddImportQuickFixTest/importAbstractContainersFromCollectionsABC/main.py
new file mode 100644
index 000000000000..254cf6b373a6
--- /dev/null
+++ b/python/testData/quickFixes/PyAddImportQuickFixTest/importAbstractContainersFromCollectionsABC/main.py
@@ -0,0 +1 @@
+my_collection: Sized = list()
diff --git a/python/testSrc/com/jetbrains/python/quickFixes/PyAddImportQuickFixTest.java b/python/testSrc/com/jetbrains/python/quickFixes/PyAddImportQuickFixTest.java
index e861098d5070..2ea9bb60c68d 100644
--- a/python/testSrc/com/jetbrains/python/quickFixes/PyAddImportQuickFixTest.java
+++ b/python/testSrc/com/jetbrains/python/quickFixes/PyAddImportQuickFixTest.java
@@ -355,6 +355,27 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
doMultiFileNegativeTest("Import");
}
+ // PY-46344
+ public void testImportAbstractContainersFromCollectionsABC() {
+ Consumer fileConsumer = file -> {
+ doMultiFileAutoImportTest("Import", fix -> {
+ final List candidates = ContainerUtil.map(fix.getCandidates(), c -> c.getPresentableText());
+ assertNotNull(candidates);
+ assertContainsElements(candidates, "collections.abc.Sized");
+ assertDoesntContain(candidates, "collections.Sized");
+ return false;
+ });
+ };
+ runWithAdditionalFileInLibDir(
+ "_collections_abc.py",
+ "__all__ = [\"Sized\"]\n" +
+ "__name__ = \"collections.abc\"\n" +
+ "class Sized:\n" +
+ " pass\n",
+ fileConsumer
+ );
+ }
+
private void doTestProposedImportsOrdering(String @NotNull ... expected) {
doMultiFileAutoImportTest("Import", fix -> {
final List candidates = ContainerUtil.map(fix.getCandidates(), c -> c.getPresentableText());