`parse.file_contents` doesn't find nested imports
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7k
- Forks
- 687
- Avg merge
- 4h 56m
- Merged PRs (30d)
- 2
Description
The parse.file_contents function (mentioned here) doesn't seem to support imports that are indented (such as in a try block or in a function). This is in contrast to identify.imports, which does seem to find these imports. The issue with using the latter is that it doesn't include comments in the return value, and I'm interested in getting import comments.
Is there an intended difference between these two functions? Is one deprecated? It looks like it might be as simple as adding .strip here or in general modifying those few lines to match how identify.imports does it. Alternatively, maybe identify.imports could be modified to return comment data?
Thanks!
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
Compare isort/parse.py around line 256 with isort/identify.py around lines 81-84 and line 95, then reproduce how parse.file_contents handles indented imports and comments. Clarify whether parse.file_contents or identify.imports is the intended entry point; done means nested imports are found without losing the import comments the issue requires.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100