-
Notifications
You must be signed in to change notification settings - Fork 770
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
[Auto Import] - Suggest equivalents from collections.abc
rather than typing
#3318
Comments
just to confirm you prefer |
Maybe they should be suggested instead of? The typing module versions are deprecated and will probably be removed eventually. |
It's unlikely that the typing versions of these symbols will ever be removed. They are too widely used. It would be incredibly disruptive to eliminate them, and there's really no real benefit to removing them. I don't think we need to be in a hurry to move away from them. I think there are two options here:
@michaeloliverx, I think you're suggesting option 2. The reason I'm reluctant to do this is because it involves some rather gross hard-coded logic that has special knowledge of these typing symbols. The right way to handle this in a general manner is 3. There are some discussions in the typing community for providing a way to mark symbols as deprecated, but they haven't yet gotten beyond the discussion phase. |
I didn't notice that the PEP and docs wording differ.
So I would agree that this isn't urgent. |
I agree that showing |
If you use pyupgrade (as we do) in your CI pipelines, this is a bit annoying, since pyupgrade fails if using python 3.10 and importing these collections from typing module |
At least having 'from collections.abc' in the suggestions would be beneficial alone. |
Still interested in this, bump @bschnurr & co. |
Lately I’ve actually noticed that sometimes it does suggest both |
If one has Python 3.9 as minimum version, Ruff’s Pyupgrade support will be able to autofix these. But I prefer to use them in new code, so they should be suggested. Also, of course not everyone uses Ruff or Pyupgrade. |
Not having the correct import in the suggestions is getting very annoying. Is there any way to convince Pylance to do this right? |
It's on our backlog so it should be fixed eventually. |
That’s great and I appreciate it. But this is disruptive enough for me that I’d like to employ a workaround if there is one. Can you think of a way to work around this? |
Out of curiosity, why are you anxious about importing from
Here's one workaround that admittedly has some downsides. You could uninstall pylance and install the pyright VS Code plugin. Pyright is the type checker upon which pylance is built. (You can't have pylance and pyright installed at the same time.) Pyright has the same core features of pylance but lacks advanced language server features like semantic highlighting and refactoring. It provides a simpler version of auto-import without indexing. Its auto-import suggestions are based on what it has previously seen in files that you've opened. If you open a file that imports from |
I just want to use non-deprecated APIs as a baseline. And I want to use them from the start instead of changing things later. Just a good practice to have. Then your software lasts longer without changing things.
Hm, I thought something along the line of putting a file with stub overrides somewhere where PyLance picks it up or so. |
For now, we will do just simple change. previously, we filtered out those types from for now, we will let both of them in the indices so auto/add imports show them as options as well. but we won't touch ordering. typing will still show up before collection.abc |
This issue has been fixed in prerelease version 2023.11.11, which we've just released. You can find the changelog here: CHANGELOG.md |
Python 3.9 allows type hinting generics in standard collections so a bunch of things from the
typing
namespace got deprecated. Pylance should correctly suggest the newer versions e.g.typing.Mapping
>collections.abc.Mapping
if the python version is >= 3.9.The text was updated successfully, but these errors were encountered: