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 does not report expected error "Could not access item in TypedDict" #1088

Closed
jensmueller-com opened this issue Mar 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

@jensmueller-com
Copy link

Environment data

  • Language Server version: 2021.3.3
  • OS and version: macOS 11.2.3
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.2

Expected behaviour

Pylance reports the following error in func1, func2, and func3:

Could not access item in TypedDict
  "nonexistent_key" is not a defined key in "TestTypedDict"

Actual behaviour

Pylance reports the expected error in func1 and func2 but not in func3.

Logs

Background analysis message: ensurePartialStubPackages
Background analysis message: setFileOpened
[FG] parsing: test.py (37ms)
[FG] parsing: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 4ms] (107ms)
[FG] binding: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/builtins.pyi (38ms)
[FG] binding: test.py (1ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens full
[BG(1)] getSemanticTokens full at test.py ...
[BG(1)]   parsing: test.py (19ms)
[BG(1)]   parsing: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 3ms] (82ms)
[BG(1)]   binding: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/builtins.pyi (30ms)
[BG(1)]   binding: test.py (1ms)
[BG(1)]   parsing: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/typing.pyi [fs read 2ms] (22ms)
[BG(1)]   binding: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/typing.pyi (10ms)
[BG(1)]   parsing: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 2ms] (10ms)
[BG(1)]   binding: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (1ms)
[BG(1)]   parsing: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stubs/typing-extensions/typing_extensions.pyi [fs read 1ms] (3ms)
[BG(1)]   binding: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stubs/typing-extensions/typing_extensions.pyi (1ms)
[BG(1)]   parsing: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/abc.pyi [fs read 1ms] (1ms)
[BG(1)]   binding: …/.vscode/extensions/ms-python.vscode-pylance-2021.3.3/dist/typeshed-fallback/stdlib/abc.pyi (0ms)
[BG(1)] getSemanticTokens full at test.py (215ms)
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 0:0 - 29:0 at test.py (1ms)
Background analysis message: analyze
[BG(1)] analyzing: test.py ...
[BG(1)]   checking: test.py (7ms)
[BG(1)] analyzing: test.py (7ms)
Background analysis message: resumeAnalysis

Code Snippet / Additional information

from typing import TypedDict


class TestClass:
    def __init__(self, **kwargs) -> None:
        pass


class TestTypedDict(TypedDict):
    key: str


dictionary: TestTypedDict = {"key": "value"}


def func1() -> TestClass:
    nonexistent_key = dictionary["nonexistent_key"]

    return TestClass(dictionary=nonexistent_key)


def func2() -> TestClass:
    test_class = TestClass(dictionary=dictionary["nonexistent_key"])

    return test_class


def func3() -> TestClass:
    return TestClass(dictionary=dictionary["nonexistent_key"])
@erictraut
Copy link
Contributor

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

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

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