Pylance cannot figure out the types in a TypedDict
Type: Bug
code from https://github.com/hunterhogan/mapFolding/blob/7ee0f72511b8ce36811bd15aa4e2a78071c0f213/mapFolding/someAssemblyRequired/toolkitNumba.py
class ParametersNumba(TypedDict):
_dbg_extend_lifetimes: NotRequired[bool]
_dbg_optnone: NotRequired[bool]
_nrt: NotRequired[bool]
boundscheck: NotRequired[bool]
cache: bool
debug: NotRequired[bool]
error_model: str
fastmath: bool
forceinline: NotRequired[bool]
forceobj: NotRequired[bool]
inline: NotRequired[str]
# locals: NotRequired[dict[str, Any]]
looplift: NotRequired[bool]
no_cfunc_wrapper: NotRequired[bool]
no_cpython_wrapper: NotRequired[bool]
no_rewrites: NotRequired[bool]
nogil: NotRequired[bool]
nopython: NotRequired[bool]
parallel: NotRequired[bool]
# pipeline_class: NotRequired[type[numbaCompilerBase]]
# signature_or_function: NotRequired[Any | Callable[..., Any] | str | tuple[Any, ...]]
target: NotRequired[str]
...
listDecoratorKeywords: list[ast.keyword] = [Make.keyword(parameterName, Make.Constant(parametersNumba[parameterName])) for parameterName in parametersNumba.keys()]
[{
"resource": "/c:/apps/mapFolding/mapFolding/someAssemblyRequired/toolkitNumba.py",
"owner": "pylance",
"code": {
"value": "reportUnknownArgumentType",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUnknownArgumentType.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 8,
"message": "Argument type is unknown\n Argument corresponds to parameter \"value\" in function \"Constant\"",
"source": "Pylance",
"startLineNumber": 248,
"startColumn": 88,
"endLineNumber": 248,
"endColumn": 118
}]
Originally
The real code is
ConstantValueType: typing_TypeAlias = bool | bytes | complex | EllipsisType | float | int | None | range | str
...
listDecoratorKeywords: list[ast.keyword] = [Make.keyword(parameterName, Make.Constant(parameterValue)) for parameterName, parameterValue in parametersNumba.items()]
Error
[{
"resource": "/c:/apps/mapFolding/mapFolding/someAssemblyRequired/toolkitNumba.py",
"owner": "pylance",
"code": {
"value": "reportArgumentType",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportArgumentType.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 8,
"message": "Argument of type \"object\" cannot be assigned to parameter \"value\" of type \"ConstantValueType\" in function \"Constant\"\n Type \"object\" is not assignable to type \"ConstantValueType\"\n \"object\" is not assignable to \"bool\"\n \"object\" is not assignable to \"bytes\"\n \"object\" is not assignable to \"complex\"\n \"object\" is not assignable to \"EllipsisType\"\n \"object\" is not assignable to \"float\"\n \"object\" is not assignable to \"int\"\n \"object\" is not assignable to \"None\"\n ...",
"source": "Pylance",
"startLineNumber": 249,
"startColumn": 88,
"endLineNumber": 249,
"endColumn": 102
}]
Hover over parametersNumba.items()
(method) def items() -> dict_items[str, object]
object is obviously a fallback value in pylance.
TypeAlias
Comment out TypedDict and add
ParametersNumba: TypeAlias = dict[str, str | bool]
No more problems. Either version of the code works.
Extension version: 2025.5.101 VS Code version: Code - Insiders 1.101.0-insider (7197360b79e6da3404ed5ad1fb4d7ea74a8bb5d2, 2025-06-04T05:03:51.910Z) OS version: Windows_NT x64 10.0.26100 Modes:
System Info
| Item | Value |
|---|---|
| CPUs | AMD Ryzen 7 5700U with Radeon Graphics (16 x 1797) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) | undefined |
| Memory (System) | 12.90GB (2.66GB free) |
| Process Argv | --crash-reporter-id 1ffa83f2-6d65-4589-b9e5-f941a87a12e2 |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt551:31249597
vscod805cf:30301675
c4g48928:30535728
962ge761:30841072
dsvsc014:30777825
dsvsc015:30821418
h48ei257:31000450
pythontbext0:30879054
cppperfnew:30980852
dwnewjupyter:31046869
pythonrstrctxt:31093868
nativeloc1:31118317
e80f6927:31120813
dwcopilot:31158714
5b1c1929:31184661
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
hdaa2157:31222309
copilot_t_ci:31222730
g012b348:31231168
pythoneinst12:31251391
bgtreat:31252123
c7cif404:31309980
pythonpulldiag:31287486
6gi0g917:31259950
61ibe868:31282443
996jf627:31264550
pythonrdcb7:31268811
usemplatestapi:31297334
jdghv92:31317040
747dc170:31275146
pythonfullctx:31296836
6518g693:31302842
pylancecolor:31288664
generatesymbolt:31280541
convertfstringf:31280702
gendocf:31280703
923gi514:31310909
b99bg931:31306656
fd45d811:31320948
a2ijf515:31307742
convertlamdat:31319677
gce3e431:31315077
Hi @hunterhogan, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
Similar Issues (FYI only, not solutions)
The following issues may or may not be related to your report. They are provided for reference only, as they may describe similar symptoms, affect the same feature, or address related concerns, but may not be the same issue.
- Pylance inappropriately complains about an empty
TypedDictinstance. https://github.com/microsoft/pylance-release/issues/4116 - Class-style TypedDict variables with NotRequired annotations are treated as Required. https://github.com/microsoft/pylance-release/issues/2469
- TypedDict type inference failing since v2022.8.10. https://github.com/microsoft/pylance-release/issues/3166
The team will respond to your issue shortly. Please note this is a trial feature and may not be fully accurate. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or was incorrect, please give it a 👎. Your feedback helps us improve!
This is unlikely a bug in pyright (the type checker that underlies pylance), but it's difficult to confirm because the code sample is incomplete. It references a bunch of symbols whose definitions are not provided. We can help you diagnose the problem if you provide a minimal, self-contained code sample as requested in the bug report template. As an added bonus, the process of creating a minimal, self-contained code sample will often help you understand the error message that you're seeing from the type checker.
Y'all don't have skin in the game.
from typing import TypedDict
class incompleteCode(TypedDict):
cache: bool
addedBonus: incompleteCode = {
'cache': True,
}
humilityIsAVirtue: int = int(x = addedBonus[list(addedBonus.keys())[0]])
print(humilityIsAVirtue)
i think you have to remove 'x='
class incompleteCode(TypedDict):
cache: bool
addedBonus: incompleteCode = {
'cache': True,
}
humilityIsAVirtue: int = int(addedBonus[list(addedBonus.keys())[0]])
print(humilityIsAVirtue)
The problem persists
[{
"resource": "/c:/apps/mapFolding/mapFolding/someAssemblyRequired/toolkitNumba.py",
"owner": "pylance",
"code": {
"value": "reportArgumentType",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportArgumentType.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 8,
"message": "Argument of type \"object\" cannot be assigned to parameter \"value\" of type \"ConstantValueType\" in function \"Constant\"\n Type \"object\" is not assignable to type \"ConstantValueType\"\n \"object\" is not assignable to \"bool\"\n \"object\" is not assignable to \"bytes\"\n \"object\" is not assignable to \"complex\"\n \"object\" is not assignable to \"EllipsisType\"\n \"object\" is not assignable to \"float\"\n \"object\" is not assignable to \"int\"\n \"object\" is not assignable to \"None\"\n ...",
"source": "Pylance",
"startLineNumber": 245,
"startColumn": 88,
"endLineNumber": 245,
"endColumn": 102
}]
Version: 1.102.0-insider (user setup) Commit: bdc1dd9a7c36b7dab7a9eeec2f05a19f7abd0409 Date: 2025-06-20T09:31:30.580Z Electron: 35.5.1 ElectronBuildId: 11727614 Chromium: 134.0.6998.205 Node.js: 22.15.1 V8: 13.4.114.21-electron.0 OS: Windows_NT x64 10.0.26100
Identifier ms-python.vscode-pylance Version 2025.6.100 Last Updated 2025-06-19, 18:17:42