Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/1505/isort crash on pyramid #1506

Merged
merged 4 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"