#270447: work around a bug in jython to fix formatting of `from . import views`
authorJulien Enselme <jenselme@netbeans.org>
Sat, 10 Jun 2017 22:44:51 +0200
changeset 18407fcbdc73e2a68
parent 18406 2b8a31fe02a4
child 18409 3863ae2b6e3a
child 18427 1520ed2e78e3
#270447: work around a bug in jython to fix formatting of `from . import views`
python.source/src/org/netbeans/modules/python/source/ImportManager.java
     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;