Pylance-release: `Dict[k, v]` vs `dict[k, v]` (!)

Created on 26 Oct 2020  路  5Comments  路  Source: microsoft/pylance-release

Environment data

  • Language Server version: 2020.10.2
  • OS and version: Windows 10 20H2
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda with Python 3.7.7

Expected behaviour

Either:

  1. No errors, if dict[k, v] is meant to be supported.
  2. An error on type expressions of the form x: dict[k, v] for being invalid.

    1. And: never infer dict[k, v] as a type.

Actual behaviour

x: Dict[str, str] = {'foo': 'bar'}
x = dict(x)
y: dict[str, str] = {'foo': 'bar'}
x = y
PyLance:
  "dict[str, str]" is incompatible with "Dict[str, str]"Pylance (reportGeneralTypeIssues)

Where:

  1. At line (1) x has type Dict[]
  2. At line (2) dict(x) has type dict[]
  3. Same at line (3) then (4) for y

Logs

Logic bug.

Code Snippet / Additional information

This template feels sort of inverted. Maybe merge "Code" and "Actual Behavior" and place them before "Expected Behavior"?

bug fixed in next version

Most helpful comment

I found and fixed the root cause of this problem. The fix will be in the next release.

All 5 comments

I'm tracking the same bug here: https://github.com/microsoft/pyright/issues/1120. The problem is that I'm not able to repro the problem, and it appears to be sporadic. I assume it has to do with some aspect of the type analyzers internal caching mechanism.

I found and fixed the root cause of this problem. The fix will be in the next release.

I've noticed the same issue with list vs List.
image

@ElijahSink I believe that'll also be fixed.

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

Was this page helpful?
0 / 5 - 0 ratings