List<QualifiedName> (PyFile containingFile) { List<QualifiedName> imports = new ArrayList<>(); for (PyFromImportStatement anImport : containingFile.getFromImports()) { final QualifiedName source = anImport.getImportSourceQName(); if (source != null) { imports.add(source); } } for (PyImportElement importElement : containingFile.getImportTargets()) { final QualifiedName qName = importElement.getImportedQName(); if (qName != null) { imports.add(qName.removeLastComponent()); } } return imports; }