diff options
| author | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2020-02-10 15:23:10 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-10 15:23:10 -0800 |
| commit | a7ce8411c3e5f6d89046501d2f2d129bf84ba5ee (patch) | |
| tree | c6f05cd3a23af4c2600159143760fedb9b96097b | |
| parent | 92a625fb975171e479a24a621b3264d0cdccbe15 (diff) | |
| parent | fb125bebae45b4c68e04b9fa78f176207c3714af (diff) | |
| download | isort-a7ce8411c3e5f6d89046501d2f2d129bf84ba5ee.tar.gz | |
Merge pull request #1131 from timothycrosley/feature/fix-as-imports-no-section
Fix issue with as_imports and force_single_section
| -rw-r--r-- | isort/output.py | 6 | ||||
| -rw-r--r-- | tests/test_isort.py | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/isort/output.py b/isort/output.py index 035224c9..8b753bcd 100644 --- a/isort/output.py +++ b/isort/output.py @@ -33,14 +33,14 @@ def sorted_imports( sections: Iterable[str] = itertools.chain(parsed.sections, config.forced_separate) if config.no_sections: - parsed.imports["no_sections"] = {"straight": [], "from": {}} + parsed.imports["no_sections"] = {"straight": {}, "from": {}} base_sections: Tuple[str, ...] = () for section in sections: if section == "FUTURE": base_sections = ("FUTURE",) continue - parsed.imports["no_sections"]["straight"].extend( - parsed.imports[section].get("straight", []) + parsed.imports["no_sections"]["straight"].update( + parsed.imports[section].get("straight", {}) ) parsed.imports["no_sections"]["from"].update(parsed.imports[section].get("from", {})) sections = base_sections + ("no_sections",) diff --git a/tests/test_isort.py b/tests/test_isort.py index d3fc6a33..88d4349a 100644 --- a/tests/test_isort.py +++ b/tests/test_isort.py @@ -4920,6 +4920,14 @@ import os assert SortImports(file_contents=test_input, no_sections=True).output == expected_output +def test_no_sections_with_as_import(): + """Test to ensure no_sections work with as import.""" + test_input = """import oumpy as np +import sympy +""" + assert SortImports(file_contents=test_input, no_sections=True).output == test_input + + def test_no_lines_too_long(): """Test to ensure no lines end up too long. See issue: #1015""" test_input = """from package1 import first_package, \ |
