diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2015-02-04 22:27:51 -0500 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2015-02-04 22:27:51 -0500 |
commit | 421b604ee3d1fc21d413b3f0f50694c465dbc64c (patch) | |
tree | c8cb6c28feae499825788bd26a15d598530b70bf | |
parent | ae4cc24d1b9f39527de43c99938f79a0757121df (diff) | |
parent | 1ab2c9f1528f329de2afd3fc6413b838a7dd630a (diff) | |
download | isort-421b604ee3d1fc21d413b3f0f50694c465dbc64c.tar.gz |
Merge latest from develop
-rw-r--r-- | ACKNOWLEDGEMENTS.md | 1 | ||||
-rw-r--r-- | isort/isort.py | 7 | ||||
-rw-r--r-- | test_isort.py | 13 |
3 files changed, 20 insertions, 1 deletions
diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md index 28690ec9..c2814401 100644 --- a/ACKNOWLEDGEMENTS.md +++ b/ACKNOWLEDGEMENTS.md @@ -39,6 +39,7 @@ Code Contributors - Kasper Jacobsen (@dinoshauer) - Sebastian Pipping (@hartwork) - Helen Sherwood-Taylor (@helenst) +- Mocker (@Zuckonit) - Tim Graham (@timgraham) Documenters diff --git a/isort/isort.py b/isort/isort.py index beb36bc5..8fafd9d0 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -594,8 +594,13 @@ class SortImports(object): def _strip_syntax(self, import_string): import_string = import_string.replace("_import", "[[i]]") - for remove_syntax in ['\\', '(', ')', ",", 'from ', 'import ']: + for remove_syntax in ['\\', '(', ')', ',']: import_string = import_string.replace(remove_syntax, " ") + import_list = import_string.split() + for key in ('from', 'import'): + if key in import_list: + import_list.remove(key) + import_string = ' '.join(import_list) import_string = import_string.replace("[[i]]", "_import") return import_string diff --git a/test_isort.py b/test_isort.py index 180c506f..7fde1b43 100644 --- a/test_isort.py +++ b/test_isort.py @@ -1181,3 +1181,16 @@ def test_sticky_comments(): "# Used for type-hinting (ref: https://github.com/davidhalter/jedi/issues/414).\n" "from selenium.webdriver.remote.webdriver import WebDriver # noqa\n") assert SortImports(file_contents=test_input).output == test_input + + +def test_zipimport(): + """Imports ending in "import" shouldn't be clobbered""" + test_input = "from zipimport import zipimport\n" + assert SortImports(file_contents=test_input).output == test_input + + +def test_from_ending(): + """Imports ending in "from" shouldn't be clobbered.""" + test_input = "from foo import get_foo_from, get_foo\n" + expected_output = "from foo import get_foo, get_foo_from\n" + assert SortImports(file_contents=test_input).output == expected_output |