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

Pylance generic type error #1121

Closed
pasunx opened this issue Apr 4, 2021 · 3 comments
Closed

Pylance generic type error #1121

pasunx opened this issue Apr 4, 2021 · 3 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

@pasunx
Copy link

pasunx commented Apr 4, 2021

Environment data

  • Language Server version: 2021.3.4
  • OS and version: win32 x64
  • Python version (and distribution if applicable, e.g. Anaconda):
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: strict

Code Snippet / Additional information

class A:

    class B: ...

    a = list["A.B"]()   # ok but no color
    b: list["A.B"] = [] # A is class but B is Unknown

A.a.append(A.B()) # ok
A.b.append(A.B()) # error:
                  #    Argument of type "B" cannot be assigned to parameter "__object" of type "Literal['A.B']" in function "append"
                  #      "B" cannot be assigned to type "Literal['A.B']" Pylance (reportGeneralTypeIssues)

image

@github-actions github-actions bot added the triage label Apr 4, 2021
@erictraut
Copy link
Contributor

Thanks for reporting the problem.

This appears to be a problem in the order of expression evaluation within pyright. The semantic highlighting is causing a different evaluation order than would otherwise occur, and this exposes a bug in the type evaluator. The problem doesn't occur (or is much harder to trigger) when semantic highlighting is disabled. I'll investigate further.

@erictraut
Copy link
Contributor

I found the source of the bug. It was a regression that I introduced about two months ago when adding support for PEP 637. It resulted in inconsistent type evaluations of string literals within type annotations based on the order in which nodes were evaluated. Pylance's semantic highlighting feature caused nodes to be visited in a different order than they otherwise would be, and that exposed the bug.

This will be fixed in the next release of Pylance.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Apr 4, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.4.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202140-7-april-2021

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