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 isinstance bug ? #1499

Closed
pasunx opened this issue Jun 25, 2021 · 2 comments
Closed

Pylance isinstance bug ? #1499

pasunx opened this issue Jun 25, 2021 · 2 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 Jun 25, 2021

Environment data

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

class AST: ...

class Foo(AST):

    value: str

class Bar(AST):

    value: AST

def handler(node: AST) -> Any:
    if isinstance(node, Foo):
        return node.value
    elif isinstance(node, Bar):
        if isinstance(node.value, Foo): # Unnecessary isinstance call; "str" is never an instance of "Foo" Pylance(reportUnnecessaryIsInstance)
            return node.value

this also.

class Baz(AST):

    value: str

class Qux(AST):

    value: int

def handler(node: AST) -> Any:
    if isinstance(node, Baz):
        result = [node.value] # type: list[str] # Expression of type "list[str]" cannot be assigned to declared type "list[int]"
                                                #  TypeVar "_T@list" is invariant
                                                #    "str" is incompatible with "int"
        return result
    elif isinstance(node, Qux):
        result = [node.value] # type: list[int]
        return result
@erictraut
Copy link
Contributor

Thanks for the bug report. This will be fixed in the next release.

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jun 26, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202170-6-july-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