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

import suggestions from ast module always shows up before typing #919

Open
DetachHead opened this issue Dec 2, 2024 · 2 comments
Open
Labels
language server LSP: import suggestions import suggestions can show as either a code action or autocomplete suggestion

Comments

@DetachHead
Copy link
Owner

there are plenty of symbols in the ast module with the same name as symbols from typing. ive wanted to avoid special-casing solutions for annoyances like this with import suggestions, but this particular situation happens often enough that it's starting to really get on my nerves, so i want to specifically handle this case.

image

@DetachHead DetachHead added language server LSP: import suggestions import suggestions can show as either a code action or autocomplete suggestion labels Dec 2, 2024
@NCBM
Copy link
Contributor

NCBM commented Dec 2, 2024

There are also some other modules provide names that are not suitable in many cases such as imp, re.{A,I,L,M,X,S,U}, ctypes.Union and so on.

One idea I can provide is to provide a configuration to specify priorities to control the order, which is kind of similar to python.analysis.packageIndexDepths provided by pylance. Here is a scratch example:

"importSuggestions.namePriorities": {
    "ast": -1,
    "imp": -1,
    "re": {
        "A": -1,
        "I": -1
    }
}

@DetachHead
Copy link
Owner Author

looking into this further, it seems that the affected symbols are TypeVar, ParamSpec and TypeVarTuple but these are only present in the ast module when targeting python >=3.12, in which case you should be using the new syntax instead anyway. there's also ast.FunctionType which conflicts with types.FunctionType but i think that type is rarely used so i don't think it's as much of a concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language server LSP: import suggestions import suggestions can show as either a code action or autocomplete suggestion
Projects
None yet
Development

No branches or pull requests

2 participants