a way to configure or remember the preferred order of import suggestions
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.
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. Here is a scratch example:
"importSuggestions.namePriorities": {
"ast": {
"*": -1
},
"imp": -1,
"re": {
"A": -1,
"I": -1
}
}
If possible, completions in vscode or something else would also benefit from this.
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.
I have a very similar annoyance that import suggestions appear in an inconvenient order. e.g. I would always like pathlib.Path to be the first suggestion.
Of course this depends on the use-case and is highly individual. Someone else might prefer anyio.Path. Overall I agree with @NCBM's idea to customize the priority to the user's preference.
An idea from #1255 that I like:
Alternatively or additionally, basedpyright could remember the most recently chosen module for a given unqualified symbol, and suggest that option first.
Fixed, thanks