diff options
author | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2019-03-02 14:59:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-02 14:59:37 -0800 |
commit | 0b36a8bcf29f092c427c5dc8f5eb6e79cfa4134b (patch) | |
tree | 69c06168cc00726bca1b4add66d5c0e332349532 | |
parent | 7f1c0da72efd378911c72bdaff81bbd36b042b83 (diff) | |
parent | 6099642ecdaa5fecefac4d573efd9f47e3befc9f (diff) | |
download | isort-0b36a8bcf29f092c427c5dc8f5eb6e79cfa4134b.tar.gz |
Merge pull request #854 from mkurnikov/fix-enum-bug-cherry-pick
Fix bug with parsing WrapModes from config file
-rw-r--r-- | isort/settings.py | 11 | ||||
-rw-r--r-- | test_isort.py | 14 |
2 files changed, 23 insertions, 2 deletions
diff --git a/isort/settings.py b/isort/settings.py index abac7a6f..3dbadd15 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -31,7 +31,7 @@ import re import warnings from distutils.util import strtobool from functools import lru_cache -from typing import Any, Dict, Iterable, List, Mapping, MutableMapping, Type +from typing import Any, Dict, Iterable, List, Mapping, MutableMapping, Callable from .utils import difference, union @@ -216,6 +216,13 @@ def _update_settings_with_config( _update_with_config_file(editor_config_file, sections, computed_settings) +def _get_str_to_type_converter(setting_name: str) -> Callable[[str], Any]: + type_converter = type(default.get(setting_name, '')) # type: Callable[[str], Any] + if type_converter == WrapModes: + type_converter = WrapModes.from_string + return type_converter + + def _update_with_config_file( file_path: str, sections: Iterable[str], @@ -243,7 +250,7 @@ def _update_with_config_file( for key, value in settings.items(): access_key = key.replace('not_', '').lower() - existing_value_type = type(default.get(access_key, '')) # type: Type[Any] + existing_value_type = _get_str_to_type_converter(access_key) if existing_value_type in (list, tuple): # sections has fixed order values; no adding or substraction from any set if access_key == 'sections': diff --git a/test_isort.py b/test_isort.py index 2959c3e0..f1f6bbe0 100644 --- a/test_isort.py +++ b/test_isort.py @@ -28,6 +28,7 @@ import posixpath import sys import sysconfig +import py import pytest from isort import finders, main, settings @@ -2826,3 +2827,16 @@ def test_noqa_issue_679(): 'import zed # NOQA\n' 'import ujson # NOQA\n') assert SortImports(file_contents=test_input).output == test_output + + +def test_extract_multiline_output_wrap_setting_from_a_config_file(tmpdir: py.path.local) -> None: + editorconfig_contents = [ + 'root = true', + ' [*.py]', + 'multi_line_output = 5' + ] + config_file = tmpdir.join('.editorconfig') + config_file.write('\n'.join(editorconfig_contents)) + + config = settings.from_path(str(tmpdir)) + assert config['multi_line_output'] == WrapModes.VERTICAL_GRID_GROUPED |