`src_path` semantics needs clarification
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7k
- Forks
- 687
- Avg merge
- 4h 56m
- Merged PRs (30d)
- 2
Description
I have added two lines to tests/unit/test_place.py to show the confusion.
In that test, the src_path is set to /home/layus/projects/isort_github_repo/isort (on my machine obviously) and contains the deprecated subfolder. (src_path is the isort folder in this repo).
I would expect this src_path to report either the isort module or the deprecated module to be THIRDPARTY. But they are all reported as FIRSTPARTY.
That is why I think that src_path should have stricter semantics. For my purposes I would prefer to never accept src_path / "__init__.py" as a valid src_path.name module, but I can see the convenience of specifying modules directly instead of their parent directory.
It is easy to switch from one semantics to the other using 'src_path/*orsrc_path.parent`.
I believe this is the confusion behind https://github.com/PyCQA/isort/issues/1696, https://github.com/PyCQA/isort/issues/2247 and https://github.com/PyCQA/isort/issues/2247.
I can patch it, but I need some decision on the desired behavior.
diff --git a/tests/unit/test_place.py b/tests/unit/test_place.py
index c850c689..876b0c8d 100644
--- a/tests/unit/test_place.py
+++ b/tests/unit/test_place.py
@@ -9,6 +9,8 @@ from isort.settings import Config
def test_module(src_path):
place_tester = partial(place.module, config=Config(src_paths=[src_path]))
assert place_tester("isort") == sections.FIRSTPARTY
+ assert place_tester("isort.deprecated") == sections.FIRSTPARTY
+ assert place_tester("deprecated") == sections.THIRDPARTY
assert place_tester("os") == sections.STDLIB
assert place_tester(".deprecated") == sections.LOCALFOLDER
assert place_tester("__future__") == sections.FUTURE
test result:
===================================================================================================== FAILURES =====================================================================================================
___________________________________________________________________________________________________ test_module ____________________________________________________________________________________________________
src_path = PosixPath('/home/layus/projects/isort_github_repo/isort')
def test_module(src_path):
place_tester = partial(place.module, config=Config(src_paths=[src_path]))
assert place_tester("isort") == sections.FIRSTPARTY
assert place_tester("isort.deprecated") == sections.FIRSTPARTY
> assert place_tester("deprecated") == sections.THIRDPARTY
E AssertionError: assert 'FIRSTPARTY' == 'THIRDPARTY'
E
E - THIRDPARTY
E + FIRSTPARTY
tests/unit/test_place.py:13: AssertionError
----------------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------------
/home/layus/projects/isort_github_repo/isort/isort isort
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort.py) = False
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort.cpython-312-x86_64-linux-gnu.so) = False
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort.abi3.so) = False
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort.so) = False
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort/__init__.py) = True
_is_module(/home/layus/projects/isort_github_repo/isort) = True
/home/layus/projects/isort_github_repo/isort/isort isort
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort) = True
_is_package(/home/layus/projects/isort_github_repo/isort) = True
_is_module(/home/layus/projects/isort_github_repo/isort) = True
/home/layus/projects/isort_github_repo/isort/deprecated deprecated
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort/deprecated.py) = False
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort/deprecated.cpython-312-x86_64-linux-gnu.so) = False
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort/deprecated.abi3.so) = False
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort/deprecated.so) = False
exists_case_sensitive(/home/layus/projects/isort_github_repo/isort/deprecated/__init__.py) = True
_is_module(/home/layus/projects/isort_github_repo/isort/deprecated) = True
============================================================================================= short test summary info ==============================================================================================
FAILED tests/unit/test_place.py::test_module - AssertionError: assert 'FIRSTPARTY' == 'THIRDPARTY'
=========================================================================================== 1 failed, 3 passed in 0.56s ============================================================================================
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/unit/test_place.py::test_module and the place.module call using Config(src_paths=[src_path]); run the failing test to reproduce the current classification. Review the src_path handling and related issue context, then agree on the intended semantics before changing the implementation. Done means the chosen behavior is documented by passing tests for isort, isort.deprecated, deprecated, and the existing cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100