Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Is there any way to disable "useImportHeuristic"? #3592

Closed
BlueHamBuger opened this issue Nov 8, 2022 · 4 comments
Closed

Is there any way to disable "useImportHeuristic"? #3592

BlueHamBuger opened this issue Nov 8, 2022 · 4 comments
Labels
waiting for user response Requires more information from user

Comments

@BlueHamBuger
Copy link

I am working on a big python project (a lot modules and only one main) and "resolving imports relative to each file" does confuse me when importing modules.
I found #253 which is the cause of it. Its seems that "useImportHeuristic" has been enabled by default:

I'm going to close this; we actually made the above change in 2021.8.2; the heuristic is now enabled for everyone, and you can delete the unused setting.
Originally posted by @jakebailey in #68 (comment)

Is there any way to disable it?

@erictraut
Copy link
Contributor

There's currently no way to disable this behavior.

Whey you say it "confuses you", what do you mean? Pylance will always attempt to resolve the import first based on import resolution paths configured in your Python environment (the sys.path list). If it's unable to resolve the import, it then walks up the tree from the location of the importing file and attempts to resolve the import from higher-level directories under the assumption that the importing module may be executed as part of script, where the script's main directory is implicitly part of the import search path.

Is this behavior leading to false negatives in your code base? Or how else do you find the behavior confusing or undesirable?

@judej judej added the waiting for user response Requires more information from user label Nov 8, 2022
@BlueHamBuger
Copy link
Author

BlueHamBuger commented Nov 9, 2022

Is this behavior leading to false negatives in your code base?

yeah, as i said, "I am working on a big python project", so there could be hundreds of .py files and the working tree is sort of complicated.
in such a project, the heuristic way to resolve the import could be annoying.

for example:

common
|    |─ utlis
|    |    |─ a.py
engine
|─ common
|    |─ formulas
|    |    |─ b.py
|─ tools
|    |─ c.py
scripts
|─ common

The sys.path contains only the root of working directory.
Inside c.py, while typing from common., both formulas and utlis will show up.
So if someone use from common.formulas import * instead of from engine.common.formulas import * by mistake, it would not be found until the code got executed.

@erictraut
Copy link
Contributor

I'd prefer not to expose a configuration knob to control this behavior, but that's an option if this turns out to be a common enough request.

I recommend moving this to the discussion forum to see what additional feedback we receive from other pylance users.

@judej
Copy link
Contributor

judej commented Dec 4, 2022

Moving this issue to discussion as an enhancement request for comments and upvotes.

@microsoft microsoft locked and limited conversation to collaborators Dec 4, 2022
@judej judej converted this issue into discussion #3708 Dec 4, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
waiting for user response Requires more information from user
Projects
None yet
Development

No branches or pull requests

3 participants