mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-03 19:37:39 +03:00
Fixed bug that leads to a spurious "unbound variable" diagnostic when a variable is assigned a value using a walrus operator and is later used in a **
call argument. This addresses #8218.
This commit is contained in:
parent
bc1fc9f22b
commit
2672441c22
@ -10680,11 +10680,16 @@ export function createTypeEvaluator(
|
||||
while (argIndex < argList.length) {
|
||||
if (argList[argIndex].argumentCategory === ArgumentCategory.UnpackedDictionary) {
|
||||
// Verify that the type used in this expression is a SupportsKeysAndGetItem[str, T].
|
||||
const argType = getTypeOfArgument(
|
||||
const argTypeResult = getTypeOfArgument(
|
||||
argList[argIndex],
|
||||
makeInferenceContext(paramDetails.unpackedKwargsTypedDictType),
|
||||
signatureTracker
|
||||
).type;
|
||||
);
|
||||
const argType = argTypeResult.type;
|
||||
|
||||
if (argTypeResult.isIncomplete) {
|
||||
isTypeIncomplete = true;
|
||||
}
|
||||
|
||||
if (isAnyOrUnknown(argType)) {
|
||||
unpackedDictionaryArgType = argType;
|
||||
|
@ -1,5 +1,7 @@
|
||||
# This sample tests assignment expressions used within arguments
|
||||
# This sample tests assignment expressions used within arguments.
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Mapping
|
||||
import collections
|
||||
|
||||
|
||||
@ -10,3 +12,12 @@ class NearestKeyDict(collections.UserDict):
|
||||
# This should generate an error because walrus operators
|
||||
# are not allowed with named arguments.
|
||||
b = list(iterable = keys := [k for k in sorted(self.data) if k >= key])
|
||||
|
||||
|
||||
@dataclass
|
||||
class DC1:
|
||||
x: str
|
||||
|
||||
|
||||
def func1(mapping: Mapping[str, dict]):
|
||||
return [DC1(temp := "x", **mapping[temp])]
|
||||
|
Loading…
Reference in New Issue
Block a user