Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: PyCQA/isort
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: PyCQA/isort
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: issue/1208-namespace-import-from-support
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 5 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 6, 2021

  1. Copy the full SHA
    9e75e4a View commit details
  2. Copy the full SHA
    d2bba7a View commit details
  3. Black

    timothycrosley committed Apr 6, 2021
    Copy the full SHA
    d9d95ec View commit details

Commits on Apr 7, 2021

  1. Copy the full SHA
    c8e6b68 View commit details

Commits on Apr 16, 2021

  1. Current progress

    timothycrosley committed Apr 16, 2021
    Copy the full SHA
    09095a5 View commit details
Showing with 18 additions and 2 deletions.
  1. +1 −0 CHANGELOG.md
  2. +3 −2 isort/place.py
  3. +14 −0 tests/unit/test_ticketed_features.py
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/
### 5.9.0 TBD
- Fixed (https://github.com/PyCQA/isort/pull/1695) added imports being added to doc string in some cases.
- Implemented #1697: Provisional support for PEP 582: skip `__pypackages__` directories by default.
- Implemented #1208: Support `from` imports being identified from `known_{section}` setting.

### 5.8.0 March 20th 2021
- Fixed #1631: as import comments can in some cases be duplicated.
5 changes: 3 additions & 2 deletions isort/place.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ def module_with_reason(name: str, config: Config = DEFAULT_CONFIG) -> Tuple[str,
return (
_forced_separate(name, config)
or _local(name, config)
or _known_pattern(name, config)
or known_pattern(name, config)
or _src_path(name, config)
or (config.default_section, "Default option in Config or universal default.")
)
@@ -49,7 +49,8 @@ def _local(name: str, config: Config) -> Optional[Tuple[str, str]]:
return None


def _known_pattern(name: str, config: Config) -> Optional[Tuple[str, str]]:
@lru_cache(maxsize=1000)
def known_pattern(name: str, config: Config) -> Optional[Tuple[str, str]]:
parts = name.split(".")
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:
14 changes: 14 additions & 0 deletions tests/unit/test_ticketed_features.py
Original file line number Diff line number Diff line change
@@ -1082,3 +1082,17 @@ def test_isort_can_push_star_imports_above_others_issue_1504():
from ._bar import All, Any, Not
"""
)


def test_isort_identifies_from_imports_against_known_section_issue_1208():
"""isort should provide a way to identify x from y, within known sections.
see: https://github.com/PyCQA/isort/issues/1208
"""
assert isort.check_code(
"""
import namespace.mymodule
from namespace import mymodule
""",
known_first_party=["namespace.mymodule"],
show_diff=True,
)