diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2019-11-06 02:39:07 -0800 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2019-11-06 02:39:07 -0800 |
commit | d7a16e59abb91dd11b790491f6779933ba920b02 (patch) | |
tree | 5d0de71a0903ae79a58533fe04c31e044b187780 | |
parent | fcb487173eaf1b15b7a5b1b58fa282d685c7b188 (diff) | |
download | isort-d7a16e59abb91dd11b790491f6779933ba920b02.tar.gz |
Fix known_x support post refactor
-rw-r--r-- | isort/finders.py | 6 | ||||
-rw-r--r-- | isort/settings.py | 15 |
2 files changed, 16 insertions, 5 deletions
diff --git a/isort/finders.py b/isort/finders.py index 15f8879d..5a3d8759 100644 --- a/isort/finders.py +++ b/isort/finders.py @@ -75,9 +75,9 @@ class KnownPatternFinder(BaseFinder): self.known_patterns: List[Tuple[Pattern[str], str]] = [] for placement in reversed(self.sections): - known_placement = KNOWN_SECTION_MAPPING.get(placement, placement) - config_key = f"known_{known_placement.lower()}" - known_patterns = list(getattr(self.config, config_key, [])) + known_placement = KNOWN_SECTION_MAPPING.get(placement, placement).lower() + config_key = f"known_{known_placement}" + known_patterns = list(getattr(self.config, config_key, self.config.known_other.get(known_placement, []))) known_patterns = [ pattern for known_pattern in known_patterns diff --git a/isort/settings.py b/isort/settings.py index 1c402d85..e9883bb9 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -109,6 +109,7 @@ class _Config: known_third_party: FrozenSet[str] = frozenset(("google.appengine.api",)) known_first_party: FrozenSet[str] = frozenset() known_standard_library: FrozenSet[str] = frozenset() + known_other: Dict[str, FrozenSet[str]] = field(default_factory=dict) multi_line_output: WrapModes = WrapModes.GRID # type: ignore forced_separate: FrozenSet[str] = frozenset() indent: str = " " * 4 @@ -226,8 +227,14 @@ class Config(_Config): indent = "\t" combined_config["indent"] = indent - # coerce all provided config values into their correct type + + known_other = {} for key, value in combined_config.items(): + # Collect all known sections beyond those that have direct entries + if key.startswith("known_") and key not in ("known_standard_library", "known_future_library", "known_third_party", "known_first_party"): + known_other[key[len("known_"):]] = frozenset(value) + + # Coerce all provided config values into their correct type default_value = _DEFAULT_SETTINGS.get(key, None) if default_value is None: continue @@ -237,8 +244,12 @@ class Config(_Config): if "directory" not in combined_config: combined_config["directory"] = os.path.basename(config_settings.get("source", None) or os.getcwd()) + # Remove any config values that are used for creating config object but aren't defined in dataclass combined_config.pop("source", None) - super().__init__(**combined_config) + for known_key in known_other.keys(): + combined_config.pop(f"known_{known_key}", None) + + super().__init__(known_other=known_other, **combined_config) def is_skipped(self, file_path: Path) -> bool: """Returns True if the file and/or folder should be skipped based on current settings.""" |