Repository: timothycrosley/isort
Pull request #640 (2018-01-24 21:13:10)

Fix 638
Allowed for "from.import foo"  by converting to "from . import" and added test for Issue 613 and a test for the new case added here.


Patch:
diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md
index 69ea03a3..e59a24b1 100644
--- a/ACKNOWLEDGEMENTS.md
+++ b/ACKNOWLEDGEMENTS.md
@@ -71,8 +71,6 @@ Code Contributors
 - Adam Chainz (@adamchainz)
 - @Brightcells
 - Jonas Trappenberg (@teeberg)
-- Andrew Konstantaras (@akonsta)
-- Jason Brackman (@jasonbrackman) 
 
 Documenters
 ===================
diff --git a/isort/isort.py b/isort/isort.py
index e7fb1c30..945b5489 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -831,6 +831,9 @@ class SortImports(object):
         self._in_top_comment = False
         while not self._at_end():
             line = self._get_line()
+            line = line.replace("from.import", "from . import")
+            line = line.replace("\t", " ").replace('import*', 'import *')
+            line = line.replace(" .import", " . import")
             statement_index = self.index
             skip_line = self._skip_line(line)
 
@@ -860,8 +863,6 @@ class SortImports(object):
                     self.out_lines.append(line)
                     continue
 
-                line = line.replace("\t", " ").replace('import*', 'import *')
-                line = line.replace(" .import", " . import")
                 if self.import_index == -1:
                     self.import_index = self.index - 1
 


Test patch:
diff --git a/test_isort.py b/test_isort.py
index 496339c1..a2b79648 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -871,6 +871,12 @@ def test_relative_import_with_space():
     """Tests the case where the relation and the module that is being imported from is separated with a space."""
     test_input = ("from ... fields.sproqet import SproqetCollection")
     assert SortImports(file_contents=test_input).output == ("from ...fields.sproqet import SproqetCollection\n")
+    test_input = ("from .import foo")
+    test_output = ("from . import foo\n")
+    assert SortImports(file_contents=test_input).output == test_output
+    test_input = ("from.import foo")
+    test_output = ("from . import foo\n")
+    assert SortImports(file_contents=test_input).output == test_output
 
 
 def test_multiline_import():
@@ -1620,7 +1626,7 @@ def test_fcntl():
 
 
 def test_import_split_is_word_boundary_aware():
-    """Test to ensure that isort splits words in a boundry aware mannor"""
+    """Test to ensure that isort splits words in a boundary aware manner"""
     test_input = ("from mycompany.model.size_value_array_import_func import \\\n"
                 "    get_size_value_array_import_func_jobs")
     test_output = SortImports(file_contents=test_input,
@@ -1673,7 +1679,7 @@ def test_alphabetic_sorting():
     options = {'force_single_line': True,
                'force_alphabetical_sort_within_sections': True, }
 
-    output = SortImports(file_contents=test_input, known_first_party=['django'], **options).output
+    output = SortImports(file_contents=test_input, **options).output
     assert output == test_input
 
     test_input = ("# -*- coding: utf-8 -*-\n"