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

Feature Request: Automatic Conversion of Relative Imports to Absolute Imports #2253

Open
nh916 opened this issue Apr 2, 2024 · 0 comments
Open

Comments

@nh916
Copy link

nh916 commented Apr 2, 2024

Description

I would like to request a new feature for isort that automatically converts relative imports to absolute imports within a Python project. This feature would enhance code readability and maintainability, especially in large projects with complex directory structures.

Problem Statement

In large and complex Python projects, relative imports can make the codebase harder to navigate and understand, especially for newcomers. Enforcing absolute imports contributes to cleaner and more understandable code. Currently, developers have to manually adjust imports or rely on code review practices to enforce the use of absolute imports, which can be time-consuming and error-prone.

Proposed Solution

I propose adding an option to isort that, when enabled, converts all relative imports in a project to absolute imports based on the project's root directory. This could be implemented as a command-line flag (e.g., --absolute-imports) that can be used in conjunction with the existing isort command to also maybe check on the CI level.

Use Case

This feature would be particularly useful in projects that prioritize code readability and maintainability, making it easier to enforce a consistent import style across the entire codebase. It would also be beneficial for projects looking to migrate from relative to absolute imports as part of refactoring efforts.

Thank you for considering this feature request. I believe it would make a valuable addition to isort and greatly benefit the Python community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant