8000 Fixed regression with `LiteralString`. It is compatible with `str` ev… · codean-io/scip-python@e33c123 · GitHub
[go: up one dir, main page]

Skip to content

Commit e33c123

Browse files
committed
Fixed regression with LiteralString. It is compatible with str even in cases where invariance is in effect.
1 parent 4b39ddb commit e33c123

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/pyright-internal/src/analyzer/typeEvaluator.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20982,7 +20982,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
2098220982
}
2098320983
}
2098420984

20985-
const concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
20985+
let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
2098620986
if (isClass(concreteSrcType) && TypeBase.isInstance(concreteSrcType)) {
2098720987
if (destType.literalValue !== undefined) {
2098820988
const srcLiteral = concreteSrcType.literalValue;
@@ -21002,7 +21002,15 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
2100221002
if (ClassType.isBuiltIn(destType, 'LiteralString')) {
2100321003
if (ClassType.isBuiltIn(concreteSrcType, 'str') && concreteSrcType.literalValue !== undefined) {
2100421004
return true;
21005+
} else if (ClassType.isBuiltIn(concreteSrcType, 'LiteralString')) {
21006+
return true;
2100521007
}
21008+
} else if (
21009+
ClassType.isBuiltIn(concreteSrcType, 'LiteralString') &&
21010+
strClassType &&
21011+
isInstantiableClass(strClassType)
21012+
) {
21013+
concreteSrcType = ClassType.cloneAsInstance(strClassType);
2100621014
}
2100721015

2100821016
if (

packages/pyright-internal/src/tests/samples/literalString1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ def func6(a: LiteralString):
7171
v2 = a[0]
7272

7373
a = "hi"
74+
75+
v3: list[str] = "1 2 3".split(" ")

0 commit comments

Comments
 (0)
0