Skip to content

Commit

Permalink
Merge pull request #1506 from PyCQA/issue/1505/isort-crash-on-pyramid
Browse files Browse the repository at this point in the history
Issue/1505/isort crash on pyramid
  • Loading branch information
timothycrosley committed Sep 29, 2020
2 parents 85c2537 + 1466a4b commit f46a076
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/
- Fixed #1482: pylama integration is not working correctly out-of-the-box.
- Fixed #1492: --check does not work with stdin source.
- Fixed #1499: isort gets confused by single line, multi-line style comments when using float-to-top.
- Fixed #1505: Support case where known_SECTION points to a section not listed in sections.

### 5.5.3 [Hotfix] September 20, 2020
- Fixed #1488: in rare cases isort can mangle `yield from` or `raise from` statements.
Expand Down
2 changes: 1 addition & 1 deletion isort/place.py
Expand Up @@ -54,7 +54,7 @@ def _known_pattern(name: str, config: Config) -> Optional[Tuple[str, str]]:
module_names_to_check = (".".join(parts[:first_k]) for first_k in range(len(parts), 0, -1))
for module_name_to_check in module_names_to_check:
for pattern, placement in config.known_patterns:
if pattern.match(module_name_to_check):
if placement in config.sections and pattern.match(module_name_to_check):
return (placement, f"Matched configured known pattern {pattern}")

return None
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_projects_using_isort.py
Expand Up @@ -127,3 +127,11 @@ def test_attrs(tmpdir):
def test_datadog_integrations_core(tmpdir):
git_clone("https://github.com/DataDog/integrations-core.git", tmpdir)
run_isort([str(tmpdir)])


def test_pyramid(tmpdir):
git_clone("https://github.com/Pylons/pyramid.git", tmpdir)
run_isort(
str(target_dir)
for target_dir in (tmpdir / "src" / "pyramid", tmpdir / "tests", tmpdir / "setup.py")
)
7 changes: 7 additions & 0 deletions tests/unit/test_place.py
Expand Up @@ -20,3 +20,10 @@ def test_extra_standard_library(src_path):
)
assert place_tester("os") == sections.STDLIB
assert place_tester("hug") == sections.STDLIB


def test_no_standard_library_placement():
assert place.module_with_reason(
"pathlib", config=Config(sections=["THIRDPARTY"], default_section="THIRDPARTY")
) == ("THIRDPARTY", "Default option in Config or universal default.")
assert place.module("pathlib") == "STDLIB"

0 comments on commit f46a076

Please sign in to comment.