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

Variable type duplicated when assigned using isinstance in ternary #920

Closed
audoh-tickitto opened this issue Feb 5, 2021 · 4 comments
Closed
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@audoh-tickitto
Copy link

audoh-tickitto commented Feb 5, 2021

Environment data

  • Language Server version: 2021.2.0
  • OS and version: Windows 10 Pro 20H2 19042.789
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.1 acquired via pyenv

Expected behaviour

  • Type should only appear once

Actual behaviour

  • Type is duplicated:
    image

Logs

N/A
(I enabled logging but didn't see any relevant output in the panel when entering the problem code; when I saved I just saw the commands run for the linter, type checker etc. I have set up)

Code Snippet / Additional information

import json
json_path = "my_json.json"
with open(json_path, "rb") as data_file:
    parsed = json.load(data_file, object_hook=json_util.object_hook)
    docs = parsed if isinstance(parsed, list) else [parsed]
@github-actions github-actions bot added the triage label Feb 5, 2021
@erictraut
Copy link
Contributor

What's happening here is that the types in the union are list[Any] and list[Unknown]. But because you have type checking disabled, we hide any Any and Unknown type arguments under the assumption that you don't want to see those additional details. I'll look at how we can elide the seemingly-redundant type from the union when displaying it.

@erictraut erictraut added bug Something isn't working and removed triage labels Feb 5, 2021
@audoh-tickitto
Copy link
Author

Cool, I didn't even realise that was off by default but did wonder why I didn't see generic types! I've just enabled it.

@erictraut
Copy link
Contributor

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 Feb 7, 2021
@jakebailey
Copy link
Member

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