-
Notifications
You must be signed in to change notification settings - Fork 765
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
Recent pylance is striking out Union
imports as deprecated
#6390
Comments
Thanks for reporting the As for the other issue, this is by design. By default, pyright doesn't mark |
Eric, thank you for your kind and detailed response. You are correct, I unwittingly checked that box as part of a more involved update to Pylance settings. I stand by the observation that while typing.List, Dict, and friends are all truly deprecated, Union is not, and as I explained above, not so easily replaced as the others. It is a shame that this is an all-or-nothing setting. I imagine that it is unlikely to change at this point but please consider adding a separate flag for Union that does not misrepresent it as deprecated. Thanks again for your help! |
This issue has been fixed in prerelease version 2024.9.101, which we've just released. You can find the changelog here: CHANGELOG.md |
The release notes state:
But this is not correct. |
@agkphysics, do you have |
Did you turn off the 'deprecateTypingAliases' setting? That's what causes the error to show up for me. |
@gwk, none of these old forms are going away. Removing them from You mentioned that |
@erictraut thank you for explaining. Can you clarify what the meaning of the bug fix is in the change log? It vaguely sounds like the intent is to undo "Recent pylance is striking out Union imports as deprecated" but I guess that was just wishful thinking on my part. |
The pylance team wrote the release notes, so we'd need to ask them for clarification, but I suspect that it's referring to the fact that I fixed the |
Yes, that's correct. We don't write our release notes by hand anymore. |
Summary
As of Python 3.12,
typing.Union
is not documented as deprecated. Furthermore, the type|
operator is not a perfect replacement forUnion
, because union can mix string and type arguments whereas|
cannot.Unfortunately, Pylance is reporting that
Union
is deprecated. It also seems to be suffering from a bug where the version number is reported as[object Object]
. Perhaps this is the reason for the error?Environment data
Code Snippet
Expected behavior
I would expect Plyance to not be so aggressive about reporting `typing.Union` as deprecated, when it really is not. It seems that this is somebody's style preference that has been turned into a non-optional warning in the language server. Please consider that the recommended `|` type operator is not a perfect replacement for `Union`, because union can mix string and type arguments whereas `|` cannot. Pylance should not report it as deprecated or strike it through. At very least, it should display a hint to turn off such aggressive warnings like this in the hover explanation.Note that
Union
is not documented as deprecated in 3.13 RC2 either. See:Actual behavior
Pylance strikes out the `Union` import and displays this message on hover: > This type is deprecated as of Python [object Object]; use "|" insteadPylanceLogs
The text was updated successfully, but these errors were encountered: