-
Notifications
You must be signed in to change notification settings - Fork 768
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
Alternative syntax for unions requires Python 3.10 or newer #513
Comments
Experiencing the same issue, pylance version: 2020.10.2 (pyright d6db7c90), Python 3.7, Django 2.2 Same as the op, we are using Django Rest Framework. The permission classes which contain the
Further related code can be found at https://github.com/encode/django-rest-framework/blob/master/rest_framework/permissions.py#L97 and near that. Even manually adding a metaclass with defined |
Thanks for the bug report. I've updated the logic so it detects the case where a class has a custom metaclass that supports the |
@erictraut The It might be an idea to limit the warning to |
@cdce8p, that's a good point. I've changed the code to suppress that error in any situation where the evaluation of the type annotation is postponed (within quotes and with |
This issue has been fixed in version 2020.10.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020103-28-october-2020 |
@jakebailey The problem is not fixed in 2020.10.3
The specific class is from DRF ( details in my comment above ). Should I create a new issue, or can we reopen this? |
@Zajozor, the case involving the Django @cdce8p, I'm able to repro this problem in pylance but not in pyright, which is strange. I suspect it's related to the semantic token highlighting implemented in pylance. I'll investigate further. |
@cdce8p, I found the root cause of the problem you reported. As I suspected, it was a bad interaction between the semantic token provider and the type evaluator. When the semantic token provider asks the type evaluator "what is the type of this token?", there are cases where we need to walk up the parse tree and evaluate the expression in a broader context. In this case, for example, we need to evaluate the entire type annotation expression so we know that the expression has a postponed evaluation. The fix is in place, and it will be included in the next release. |
@erictraut Thanks for spending the time investigating and fixing the issue 👍 |
This issue has been fixed in version 2020.11.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020110-4-november-2020 |
For those wondering about the DRF Stubs issue, a very temporary fix is it edit your stubs locally, just go to |
@erictraut There still seems to be an issue when using more the two types. from __future__ import annotations
var: int | str | list | None = None This would be a valid syntax: https://www.python.org/dev/peps/pep-0604/#simplified-syntax |
@cdce8p, this is a different issue. You're using |
Thank you soo much!!! This worked for me! |
Envirement data
My django program also alert this and I don't know why, I want to know why and how to ignore this warning?
The text was updated successfully, but these errors were encountered: