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

No error on duplicate imports #6452

Closed
mjbvz opened this issue Sep 24, 2024 · 3 comments
Closed

No error on duplicate imports #6452

mjbvz opened this issue Sep 24, 2024 · 3 comments
Assignees

Comments

@mjbvz
Copy link

mjbvz commented Sep 24, 2024

  1. Turn on analysis
  2. Create a file:
from os.path import join
from os import path
from os.path import join
from os import abort as join

Bug
There are no errors reported about join being imported multiple times

Maybe not a runtime error but seems like a programing mistake we should catch. Also when you run organize imports, it shifts the import order which changes the behavior of the code :/

@mjbvz mjbvz changed the title No error when duplicate imports No error on duplicate imports Sep 24, 2024
@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Sep 25, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 25, 2024
@erictraut
Copy link
Contributor

This is legal Python code, and it doesn't violate any static typing rules.

If you'd like to enforce a rule like "no duplicate import symbols", that's something that would be more in the domain of a linter. Popular linters for Python code include pylint and ruff. Pyright (the static analysis tool upon which pylance is built) is a type checker, so it focuses on type analysis and type violations.

@mjbvz
Copy link
Author

mjbvz commented Sep 25, 2024

Ok with pushing this to a linter but running organize imports breaks the code by changing which import is resolved in the body of my program

@erictraut
Copy link
Contributor

With static type checking turned on, you should see errors if your code is broken by changing the order of imports.

@debonte debonte added by design and removed needs repro Issue has not been reproduced yet labels Sep 25, 2024
@debonte debonte closed this as completed Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants