#270447: work around a bug in jython to fix formatting of `from . import views`
1.1 --- a/python.source/src/org/netbeans/modules/python/source/ImportManager.java Tue May 30 15:45:52 2017 +0300
1.2 +++ b/python.source/src/org/netbeans/modules/python/source/ImportManager.java Sat Jun 10 22:44:51 2017 +0200
1.3 @@ -777,7 +777,12 @@
1.4 // TODO - look up for imp.getInternalModule()!
1.5 boolean isSystemLibrary = systemLibsFirst && index.isSystemModule(imp.getInternalModule());
1.6 for (alias at : names) {
1.7 - ImportEntry importEntry = new ImportEntry(imp.getInternalModule(), at.getInternalName(), at.getInternalAsname(), isSystemLibrary,
1.8 + // In imports like `from . import views` imp.getInternalModule returns an empty string instead of `.`.
1.9 + // This caused the formated import to become `from import views`. While waiting for this to be fixed in
1.10 + // jython, we work around it here.
1.11 + // See: https://netbeans.org/bugzilla/show_bug.cgi?id=270447
1.12 + String internalModule = "".equals(imp.getInternalModule()) ? "." : imp.getInternalModule();
1.13 + ImportEntry importEntry = new ImportEntry(internalModule, at.getInternalName(), at.getInternalAsname(), isSystemLibrary,
1.14 removeDuplicates ? null : imp, sortImports ? 0 : ordinal++);
1.15 if (!separateFromImps) {
1.16 importEntry.sortedFrom = false;