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

Yellow underline with reportUndefinedVariable when creating __eq__ method on dataclass #491

Closed
blackary opened this issue Oct 14, 2020 · 11 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@blackary
Copy link

Environment data

  • Language Server version: 2020.10.0
  • OS and version: OSX 10.15.6
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.2

Expected behaviour

No yellow underline when defining __eq__ method on a dataclass

Actual behaviour

Yellow underline appears, with "__eq__" is not definedPylance (reportUndefinedVariable)

Code Snippet / Additional information

from dataclasses import dataclass


@dataclass
class A:
    x: int

    def __eq__(self, other: "A") -> bool:
        return self.x == other.x


class B:
    x: int

    def __eq__(self, other: "B") -> bool:
        return self.x == other.x

Yellow underline appears on dataclass class, but not on non-dataclass class.

image

@jakebailey
Copy link
Member

I believe this is the same as microsoft/pyright#1098 and should be fixed in our release today.

@jakebailey
Copy link
Member

jakebailey commented Oct 14, 2020

Nope, I'm wrong. It's not fixed (but it is related).

image

@jakebailey
Copy link
Member

jakebailey commented Oct 14, 2020

This is related to semantic highlighting, if you set the following the message will go away on a reload.

{
	"[python]": {
        "editor.semanticHighlighting.enabled": false,
    }
}

@huguesv

@jakebailey jakebailey added bug Something isn't working needs investigation Could be an issue - needs investigation labels Oct 14, 2020
@github-actions github-actions bot removed the triage label Oct 14, 2020
@erictraut
Copy link
Contributor

@jakebailey, are you able to repro this in pylance with the latest code?

@jakebailey
Copy link
Member

jakebailey commented Oct 14, 2020

Yes, that's what the screenshots are of above, just our code at the latest. This repro is consistent, at least from my testing.

I have a "fix" that just suppresses all diagnostics during the semantic token walk which I think would solve this once and for all, so long as the semantic token pass isn't produce diagnostics that the background isn't.

@erictraut
Copy link
Contributor

Yeah, that's not the right fix. That will simply suppress what is a real bug.

This is likely a real bug in the type evaluator triggered by a particular order of evaluation that the semantic token code is using. If I can find a repro, I should be able to fix it in short order. I wasn't able to repro the other similar bug with the latest code.

@jakebailey
Copy link
Member

IIRC we disable the background thread on debug (because node doesn't make it easy to debug it), and that's where the diagnostics / semantic tokenization happens. That probably doesn't help in trying to find the issue. 🙁

@erictraut
Copy link
Contributor

Yeah, I temporarily disable the background analysis when I'm debugging issues like this.

@jakebailey
Copy link
Member

Oh, what am I saying, I ran this in debug mode (I didn't make a VSIX or anything), so there's at least some hope.

@erictraut
Copy link
Contributor

This was a bug in the semantic token provider. It was calling the type evaluator to evaluate the type of an expression, but it wasn't passing an expression node. I've made the type evaluator more resilient so it can handle this case. This was an easier and more robust way to fix this than finding all the places where the caller was passing a non-expression node.

The fix will be in the next release of pylance.

@erictraut erictraut added fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed needs investigation Could be an issue - needs investigation labels Oct 16, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.10.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020102-21-october-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants