Skip to content

TypedDict hover text does not show docstrings for inherited key type hints #5006

@fdintino

Description

@fdintino

Environment data

  • Language Server version: 2023.10.40
  • OS and version: macOS 12.7
  • Python version: 3.11

Code Snippet

from typing import TypedDict


class Foo(TypedDict, total=False):
    optional: str
    """An optional attribute"""


class Bar(Foo):
    required: str
    """A required attribute"""


def some_function(bar: Bar):
    pass


some_function({
    "required": "",
    "optional": "",
})
Screen Shot 2023-10-25 at 1 24 50 PM Screen Shot 2023-10-25 at 1 24 58 PM

Expected behavior

Hovering over a TypedDict key should show that key's docstring, regardless of whether it was defined in the body of the literal type or if it was inherited.

Actual behavior

The hover text shows type information for all keys, but only displays the docstring if the attribute is in the body of the literal TypedDict. It is not displayed if it is defined in an inherited TypedDict base class. This problem is especially vexing because the only way to define TypedDicts with a mix of required and optional keys is using inheritance, per PEP 589.

The totality flag only applies to items defined in the body of the TypedDict definition. Inherited items won’t be affected, and instead use totality of the TypedDict type where they were defined. This makes it possible to have a combination of required and non-required keys in a single TypedDict type.

Logs

Click to expand
2023-10-25 13:41:50.726 [info] [Info  - 1:41:50 PM] (43175) Pylance language server 2023.10.40 (pyright 088ebaa5) starting
2023-10-25 13:41:50.726 [info] [Info  - 1:41:50 PM] (43175) Server root directory: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist
2023-10-25 13:41:50.732 [info] [Info  - 1:41:50 PM] (43175) Starting service instance "demo-vscode-typeddict-bug"
2023-10-25 13:41:50.810 [info] (43175) No configuration file found.
2023-10-25 13:41:50.810 [info] (43175) No pyproject.toml file found.
2023-10-25 13:41:50.810 [info] [Info  - 1:41:50 PM] (43175) Setting pythonPath for service "demo-vscode-typeddict-bug": "/Users/fdintino/src/python/demo-vscode-typeddict-bug/venv/bin/python"
2023-10-25 13:41:50.811 [info] [Info  - 1:41:50 PM] (43175) Setting environmentName for service "demo-vscode-typeddict-bug": "3.11.3 (venv venv)"
2023-10-25 13:41:50.897 [info] [Info  - 1:41:50 PM] (43175) Assuming Python version 3.11
2023-10-25 13:41:50.898 [info] (43175) Assuming Python platform Darwin
2023-10-25 13:41:51.022 [info] [Info  - 1:41:51 PM] (43175) Search paths for /Users/fdintino/src/python/demo-vscode-typeddict-bug
2023-10-25 13:41:51.022 [info] [Info  - 1:41:51 PM] (43175)   /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib
2023-10-25 13:41:51.022 [info] [Info  - 1:41:51 PM] (43175)   /Users/fdintino/src/python/demo-vscode-typeddict-bug
2023-10-25 13:41:51.023 [info] [Info  - 1:41:51 PM] (43175)   /Users/fdintino/src/python/demo-vscode-typeddict-bug/typings
2023-10-25 13:41:51.023 [info] [Info  - 1:41:51 PM] (43175)   /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stubs/...
2023-10-25 13:41:51.024 [info] [Info  - 1:41:51 PM] (43175)   /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/bundled/stubs
2023-10-25 13:41:51.024 [info] [Info  - 1:41:51 PM] (43175)   /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11
2023-10-25 13:41:51.024 [info] [Info  - 1:41:51 PM] (43175)   /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload
2023-10-25 13:41:51.025 [info] [Info  - 1:41:51 PM] (43175)   /Users/fdintino/src/python/demo-vscode-typeddict-bug/venv/lib/python3.11/site-packages
2023-10-25 13:41:51.025 [info] [Info  - 1:41:51 PM] (43175) Adding fs watcher for library directories:
 /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11
/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload
/Users/fdintino/src/python/demo-vscode-typeddict-bug/venv/lib/python3.11/site-packages
2023-10-25 13:41:51.025 [info] [Info  - 1:41:51 PM] (43175) Adding fs watcher for directories:
 /Users/fdintino/src/python/demo-vscode-typeddict-bug
2023-10-25 13:41:51.025 [info] (43175) Searching for source files
2023-10-25 13:41:51.029 [info] [Info  - 1:41:51 PM] (43175) Auto-excluding /Users/fdintino/src/python/demo-vscode-typeddict-bug/venv
2023-10-25 13:41:51.032 [info] [Info  - 1:41:51 PM] (43175) Found 1 source file
2023-10-25 13:41:51.033 [info] (43175) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2023-10-25 13:41:51.033 [info] (43175) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2023-10-25 13:41:51.096 [info] (43175) [FG] parsing: /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py (25ms)
2023-10-25 13:41:51.229 [info] (43175) [FG] parsing: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 4ms] (125ms)
2023-10-25 13:41:51.264 [info] (43175) [FG] binding: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/builtins.pyi (41ms)
2023-10-25 13:41:51.267 [info] (43175) [FG] binding: /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py (1ms)
2023-10-25 13:41:51.529 [info] (43175) pytest configurations: {"message":"request cancelled","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2023-10-25 13:41:51.574 [info] (43175) [BG(1)] getSemanticTokens full at /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py ...
2023-10-25 13:41:51.574 [info] (43175) [BG(1)]   parsing: /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py (43ms)
2023-10-25 13:41:51.650 [info] (43175) [BG(1)]   parsing: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 2ms] (75ms)
2023-10-25 13:41:51.716 [info] (43175) [BG(1)]   binding: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/builtins.pyi (62ms)
2023-10-25 13:41:51.719 [info] (43175) [BG(1)]   binding: /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py (1ms)
2023-10-25 13:41:51.743 [info] (43175) [IDX(2)] scan packages /Users/fdintino/src/python/demo-vscode-typeddict-bug ...
2023-10-25 13:41:51.745 [info] (43175) [IDX(2)]   read stdlib indices (70ms)
2023-10-25 13:41:51.783 [info] (43175) [BG(1)]   parsing: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/typing.pyi [fs read 1ms] (56ms)
2023-10-25 13:41:51.809 [info] (43175) [BG(1)]   binding: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/typing.pyi (24ms)
2023-10-25 13:41:51.836 [info] (43175) [BG(1)]   parsing: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/typing_extensions.pyi [fs read 2ms] (18ms)
2023-10-25 13:41:51.842 [info] (43175) [BG(1)]   binding: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/typing_extensions.pyi (5ms)
2023-10-25 13:41:51.881 [info] (43175) [BG(1)]   parsing: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 1ms] (9ms)
2023-10-25 13:41:51.891 [info] (43175) [BG(1)]   binding: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (9ms)
2023-10-25 13:41:51.902 [info] (43175) [BG(1)]   parsing: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/types.pyi [fs read 1ms] (11ms)
2023-10-25 13:41:51.909 [info] (43175) [BG(1)]   binding: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/types.pyi (7ms)
2023-10-25 13:41:51.922 [info] (43175) [BG(1)]   parsing: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/abc.pyi [fs read 0ms] (2ms)
2023-10-25 13:41:51.923 [info] (43175) [BG(1)]   binding: /Users/fdintino/.vscode/extensions/ms-python.vscode-pylance-2023.10.40/dist/typeshed-fallback/stdlib/abc.pyi (1ms)
2023-10-25 13:41:51.944 [info] (43175) [BG(1)] getSemanticTokens full at /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py (412ms)
2023-10-25 13:41:52.047 [info] (43175) [BG(1)] analyzing: /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py ...
2023-10-25 13:41:52.047 [info] (43175) [BG(1)]   checking: /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py ...
2023-10-25 13:41:52.047 [info] (43175) [BG(1)]     parsing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/typing.py [fs read 2ms] (87ms)
2023-10-25 13:41:52.081 [info] (43175) [BG(1)]     binding: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/typing.py (33ms)
2023-10-25 13:41:52.122 [info] (43175) [BG(1)]   checking: /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py (176ms)
2023-10-25 13:41:52.123 [info] (43175) [BG(1)] analyzing: /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py (176ms)
2023-10-25 13:41:52.126 [info] (43175) [BG(1)] getSemanticTokens range 0:0 - 21:0 at /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py (2ms)
2023-10-25 13:41:52.130 [info] (43175) [BG(1)] indexing: /Users/fdintino/src/python/demo-vscode-typeddict-bug/example.py [found 3] (4ms)
2023-10-25 13:41:52.133 [info] (43175) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2023-10-25 13:41:52.301 [info] (43175) [IDX(2)] scan packages /Users/fdintino/src/python/demo-vscode-typeddict-bug (602ms)
2023-10-25 13:41:52.327 [info] (43175) Loading ONNX runtime...
2023-10-25 13:41:52.327 [info] (43175) Loaded ONNX runtime. Creating IntelliCode session...
2023-10-25 13:41:52.341 [info] (43175) [IDX(2)] index packages /Users/fdintino/src/python/demo-vscode-typeddict-bug ...
2023-10-25 13:41:52.342 [info] (43175) [IDX(2)]   index execution environment /Users/fdintino/src/python/demo-vscode-typeddict-bug ...
2023-10-25 13:41:52.342 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/__phello__/__init__.py [skipped: no '__all__' defined] (1ms)
2023-10-25 13:41:52.342 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/__init__.py [skipped: no '__all__' defined] (1ms)
2023-10-25 13:41:52.342 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/distutils/__init__.py [skipped: no '__all__' defined] (0ms)
2023-10-25 13:41:52.343 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/idlelib/__init__.py [skipped: no '__all__' defined] (1ms)
2023-10-25 13:41:52.344 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib2to3/__init__.py [skipped: no '__all__' defined] (0ms)
2023-10-25 13:41:52.344 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pydoc_data/__init__.py [skipped: no '__all__' defined] (0ms)
2023-10-25 13:41:52.345 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/test/__init__.py [skipped: no '__all__' defined] (0ms)
2023-10-25 13:41:52.345 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/turtledemo/__init__.py [skipped: no '__all__' defined] (1ms)
2023-10-25 13:41:52.346 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/__init__.py [skipped: no '__all__' defined] (0ms)
2023-10-25 13:41:52.346 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/wsgiref/__init__.py [skipped: no '__all__' defined] (1ms)
2023-10-25 13:41:52.347 [info] (43175) [IDX(2)]     indexing: /usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/xmlrpc/__init__.py [skipped: no '__all__' defined] (0ms)
2023-10-25 13:41:52.347 [info] (43175) [IDX(2)]   index execution environment /Users/fdintino/src/python/demo-vscode-typeddict-bug [found 98 in 4 files] (9ms)
2023-10-25 13:41:52.348 [info] (43175) [IDX(2)] index packages /Users/fdintino/src/python/demo-vscode-typeddict-bug [found 98 in 1 exec envs] (15ms)
2023-10-25 13:41:52.470 [info] 2023-10-25 13:41:52.468092 [I:onnxruntime:, inference_session.cc:328 operator()] Flush-to-zero and denormal-as-zero are off

2023-10-25 13:41:52.470 [info] 2023-10-25 13:41:52.469646 [I:onnxruntime:, inference_session.cc:336 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true
2023-10-25 13:41:52.469758 [I:onnxruntime:, inference_session.cc:354 ConstructorCommon] Dynamic block base set to 0

2023-10-25 13:41:52.522 [info] 2023-10-25 13:41:52.521684 [I:onnxruntime:, inference_session.cc:1400 Initialize] Initializing session.

2023-10-25 13:41:52.523 [info] 2023-10-25 13:41:52.521807 [I:onnxruntime:, inference_session.cc:1437 Initialize] Adding default CPU execution provider.

2023-10-25 13:41:52.578 [info] 2023-10-25 13:41:52.576995 [I:onnxruntime:, graph.cc:3556 CleanUnusedInitializersAndNodeArgs] Removing initializer 'pred_embedding_to_output_layer/einsum_1/mul/x:0'. It is no longer used by any node.

2023-10-25 13:41:52.588 [info] 2023-10-25 13:41:52.587320 [I:onnxruntime:, graph.cc:3619 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'rnn/transpose'. It is no longer used by any node.

2023-10-25 13:41:52.588 [info] 2023-10-25 13:41:52.587478 [I:onnxruntime:, graph.cc:3619 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Gather_out0'. It is no longer used by any node.
2023-10-25 13:41:52.587588 [I:onnxruntime:, graph.cc:3619 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Transpose_out0'. It is no longer used by any node.

2023-10-25 13:41:52.624 [info] 2023-10-25 13:41:52.623586 [V:onnxruntime:, session_state.cc:1142 VerifyEachNodeIsAssignedToAnEp] Node placements

2023-10-25 13:41:52.625 [info] 2023-10-25 13:41:52.623751 [V:onnxruntime:, session_state.cc:1145 VerifyEachNodeIsAssignedToAnEp]  All nodes placed on [CPUExecutionProvider]. Number of nodes: 56

2023-10-25 13:41:52.633 [info] 2023-10-25 13:41:52.632469 [V:onnxruntime:, session_state.cc:126 CreateGraphInfo] SaveMLValueNameIndexMapping

2023-10-25 13:41:52.634 [info] 2023-10-25 13:41:52.632975 [V:onnxruntime:, session_state.cc:172 CreateGraphInfo] Done saving OrtValue mappings.

2023-10-25 13:41:52.635 [info] 2023-10-25 13:41:52.634144 [I:onnxruntime:, allocation_planner.cc:2401 CreateGraphPartitioner] Use DeviceBasedPartition as default

2023-10-25 13:41:52.638 [info] 2023-10-25 13:41:52.637025 [I:onnxruntime:, session_state_utils.cc:201 SaveInitializedTensors] Saving initialized tensors.

2023-10-25 13:41:52.668 [info] 2023-10-25 13:41:52.666806 [I:onnxruntime:, session_state_utils.cc:345 SaveInitializedTensors] Done saving initialized tensors

2023-10-25 13:41:52.674 [info] 2023-10-25 13:41:52.673380 [I:onnxruntime:, inference_session.cc:1774 Initialize] Session successfully initialized.

2023-10-25 13:41:52.675 [info] (43175) Created IntelliCode session.
2023-10-25 13:41:52.675 [info] (43175) Initialize deeplearning succeeded

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixed in next version (release)A fix has been implemented and will appear in an upcoming version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions