@zzzen/pyright-internal 1.2.0-dev.20261108 → 1.2.0-dev.20261122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/binder.d.ts +2 -0
- package/dist/analyzer/binder.js +238 -18
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +28 -3
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +1 -1
- package/dist/analyzer/constructors.js +68 -9
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/enums.d.ts +10 -3
- package/dist/analyzer/enums.js +389 -2
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/operations.js +81 -4
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +9 -1
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +12 -3
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +1 -0
- package/dist/analyzer/protocols.js +171 -10
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scope.d.ts +3 -0
- package/dist/analyzer/scope.js +28 -6
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/sentinel.d.ts +4 -2
- package/dist/analyzer/sentinel.js +46 -28
- package/dist/analyzer/sentinel.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +4 -1
- package/dist/analyzer/symbol.js +8 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/tupleComparison.js +69 -85
- package/dist/analyzer/tupleComparison.js.map +1 -1
- package/dist/analyzer/typeEvaluator/collectionInference.d.ts +1 -1
- package/dist/analyzer/typeEvaluator/collectionInference.js +162 -87
- package/dist/analyzer/typeEvaluator/collectionInference.js.map +1 -1
- package/dist/analyzer/typeEvaluator/evaluatorCore.js +6 -0
- package/dist/analyzer/typeEvaluator/evaluatorCore.js.map +1 -1
- package/dist/analyzer/typeEvaluator/expressionEvaluation.d.ts +1 -1
- package/dist/analyzer/typeEvaluator/expressionEvaluation.js +8 -4
- package/dist/analyzer/typeEvaluator/expressionEvaluation.js.map +1 -1
- package/dist/analyzer/typeEvaluator/internals.d.ts +1 -0
- package/dist/analyzer/typeEvaluator/specialFormCreation.js +11 -0
- package/dist/analyzer/typeEvaluator/specialFormCreation.js.map +1 -1
- package/dist/analyzer/typeEvaluator/typeCompatibility.js +14 -1
- package/dist/analyzer/typeEvaluator/typeCompatibility.js.map +1 -1
- package/dist/analyzer/typeEvaluator/typeGuardNarrowing.d.ts +3 -1
- package/dist/analyzer/typeEvaluator/typeGuardNarrowing.js +88 -7
- package/dist/analyzer/typeEvaluator/typeGuardNarrowing.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +1 -1
- package/dist/analyzer/typeEvaluator.js +241 -22
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +2 -2
- package/dist/analyzer/typeGuards.js +45 -14
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.js +23 -20
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +15 -2
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +16 -2
- package/dist/analyzer/types.js +34 -4
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/languageInfoUtils.js +1 -1
- package/dist/common/languageInfoUtils.js.map +1 -1
- package/dist/common/processUtils.d.ts +1 -0
- package/dist/common/processUtils.js +38 -0
- package/dist/common/processUtils.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +6 -0
- package/dist/common/realFileSystem.js +83 -1
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/windowsProcessTree.json +20 -2
- package/dist/languageService/documentSymbolCollector.js +1 -1
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/renameProvider.js +1 -1
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +1 -1
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/localization/localize.d.ts +8 -0
- package/dist/localization/localize.js +10 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +8 -0
- package/dist/localization/package.nls.de.json +8 -0
- package/dist/localization/package.nls.en-us.json +8 -0
- package/dist/localization/package.nls.es.json +8 -0
- package/dist/localization/package.nls.fr.json +8 -0
- package/dist/localization/package.nls.it.json +8 -0
- package/dist/localization/package.nls.ja.json +8 -0
- package/dist/localization/package.nls.ko.json +8 -0
- package/dist/localization/package.nls.pl.json +8 -0
- package/dist/localization/package.nls.pt-br.json +8 -0
- package/dist/localization/package.nls.qps-ploc.json +8 -0
- package/dist/localization/package.nls.ru.json +8 -0
- package/dist/localization/package.nls.tr.json +8 -0
- package/dist/localization/package.nls.zh-cn.json +8 -0
- package/dist/localization/package.nls.zh-tw.json +8 -0
- package/dist/parser/parseNodes.d.ts +3 -4
- package/dist/parser/parseNodes.js +6 -11
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parseTreeTokenReuse.js +3 -0
- package/dist/parser/parseTreeTokenReuse.js.map +1 -1
- package/dist/parser/parser.d.ts +3 -0
- package/dist/parser/parser.js +137 -36
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.js +11 -13
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/tests/checker.test.js +19 -2
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/localizer.test.js +23 -0
- package/dist/tests/localizer.test.js.map +1 -1
- package/dist/tests/parser.test.js +357 -1
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +22 -0
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +32 -0
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +33 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +16 -2
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +36 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +7 -1
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +24 -0
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +244 -17
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +56 -12
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/tests/typeUtils.test.js +73 -0
- package/dist/tests/typeUtils.test.js.map +1 -1
- package/dist/typeServer/stubGenerator.d.ts +9 -0
- package/dist/typeServer/stubGenerator.js +90 -0
- package/dist/typeServer/stubGenerator.js.map +1 -1
- package/package.json +2 -2
|
@@ -537,7 +537,9 @@ test.each([false, true])('Protocol36CacheReuse positiveFirst=%s', (positiveFirst
|
|
|
537
537
|
assert.strictEqual(assign(acceptedType), true);
|
|
538
538
|
const diagnostics = new diagnostic_1.DiagnosticAddendum();
|
|
539
539
|
assert.strictEqual(assign(rejectedType, diagnostics), false);
|
|
540
|
-
|
|
540
|
+
const diagnosticText = diagnostics.getString();
|
|
541
|
+
expect(diagnosticText).toContain('"__iter__" is an incompatible type');
|
|
542
|
+
expect(diagnosticText).toContain('Type "() -> Iterator[int]" is not assignable to type "() -> Iterator[str | NestedSequence[str]]"');
|
|
541
543
|
assert.ok(constraints.isSame(originalConstraints));
|
|
542
544
|
assert.strictEqual(assign(rejectedType), false);
|
|
543
545
|
assert.strictEqual(assign(acceptedType), true);
|
|
@@ -547,6 +549,57 @@ test.each([false, true])('Protocol36CacheReuse positiveFirst=%s', (positiveFirst
|
|
|
547
549
|
assert.strictEqual(evaluator.printType(evaluator.solveAndApplyConstraints(typeParam, inferredConstraints)), 'int');
|
|
548
550
|
}
|
|
549
551
|
});
|
|
552
|
+
test('ProtocolMethodTypeParamBound', () => {
|
|
553
|
+
const code = `
|
|
554
|
+
// @filename: test.py
|
|
555
|
+
//// from typing import Protocol
|
|
556
|
+
////
|
|
557
|
+
//// class Expected(Protocol):
|
|
558
|
+
//// def f[U: str](self, value: U) -> U: ...
|
|
559
|
+
////
|
|
560
|
+
//// class Actual:
|
|
561
|
+
//// def f[U: int](self, value: U) -> U: ...
|
|
562
|
+
////
|
|
563
|
+
//// def check(source: Actual):
|
|
564
|
+
//// invalid: Expected = source
|
|
565
|
+
`;
|
|
566
|
+
const state = (0, testState_1.parseAndGetTestState)(code).state;
|
|
567
|
+
const file = state.testData.files[0];
|
|
568
|
+
const results = TestUtils.getAnalysisResults(state.program, [file.fileUri], state.configOptions);
|
|
569
|
+
TestUtils.validateResults(results, 1);
|
|
570
|
+
const message = results[0].errors[0].message;
|
|
571
|
+
expect(message).toContain('"f" is an incompatible type');
|
|
572
|
+
expect(message).toContain('Type "U@f" is not assignable to type "int"');
|
|
573
|
+
});
|
|
574
|
+
test('ProtocolMethodParamNameAndKind', () => {
|
|
575
|
+
const code = `
|
|
576
|
+
// @filename: test.py
|
|
577
|
+
//// from typing import Protocol
|
|
578
|
+
////
|
|
579
|
+
//// class NameProto[T](Protocol):
|
|
580
|
+
//// def f(self, x: T) -> None: ...
|
|
581
|
+
////
|
|
582
|
+
//// class NameImpl:
|
|
583
|
+
//// def f(self, y: int) -> None: ...
|
|
584
|
+
////
|
|
585
|
+
//// class KindProto[T](Protocol):
|
|
586
|
+
//// def f(self, *, x: T) -> None: ...
|
|
587
|
+
////
|
|
588
|
+
//// class KindImpl:
|
|
589
|
+
//// def f(self, x: int, /) -> None: ...
|
|
590
|
+
////
|
|
591
|
+
//// def check(a: NameImpl, b: KindImpl):
|
|
592
|
+
//// v1: NameProto[int] = a
|
|
593
|
+
//// v2: KindProto[int] = b
|
|
594
|
+
`;
|
|
595
|
+
const state = (0, testState_1.parseAndGetTestState)(code).state;
|
|
596
|
+
const file = state.testData.files[0];
|
|
597
|
+
const results = TestUtils.getAnalysisResults(state.program, [file.fileUri], state.configOptions);
|
|
598
|
+
TestUtils.validateResults(results, 2);
|
|
599
|
+
const [nameError, kindError] = results[0].errors;
|
|
600
|
+
expect(nameError.message).toContain('Type "(y: int) -> None" is not assignable to type "(x: T@NameProto) -> None"');
|
|
601
|
+
expect(kindError.message).toContain('Type "(x: int, /) -> None" is not assignable to type "(*, x: T@KindProto) -> None"');
|
|
602
|
+
});
|
|
550
603
|
test.each([
|
|
551
604
|
['list[int]', false],
|
|
552
605
|
['list[list[int]]', false],
|
|
@@ -715,6 +768,60 @@ test('Protocol55UntypedDecorators', () => {
|
|
|
715
768
|
const untypedDecoratorErrors = analysisResults[0].errors.filter((diag) => diag.getRule() === diagnosticRules_1.DiagnosticRule.reportUntypedClassDecorator);
|
|
716
769
|
assert.deepStrictEqual(untypedDecoratorErrors.map((diag) => diag.range.start.line), [127, 135, 142, 149, 158, 165, 190]);
|
|
717
770
|
});
|
|
771
|
+
test('Protocol56', () => {
|
|
772
|
+
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['protocol56.py']);
|
|
773
|
+
TestUtils.validateResults(analysisResults, 4);
|
|
774
|
+
const defaultTypeError = analysisResults[0].errors.find((error) => error.message.includes('"list[object]"'));
|
|
775
|
+
assert.strictEqual(defaultTypeError?.getRule(), diagnosticRules_1.DiagnosticRule.reportArgumentType);
|
|
776
|
+
});
|
|
777
|
+
test.each(['source', 'destination'].flatMap((side) => ['Any', 'int'].flatMap((defaultType) => [false, true].flatMap((diagnostics) => [false, true].map((positiveFirst) => ({ side, defaultType, diagnostics, positiveFirst }))))))('ProtocolDefaultCache $side default=$defaultType diagnostics=$diagnostics positiveFirst=$positiveFirst', ({ side, defaultType, diagnostics, positiveFirst }) => {
|
|
778
|
+
const sourceIsGeneric = side === 'source';
|
|
779
|
+
const state = (0, testState_1.parseAndGetTestState)(`
|
|
780
|
+
// @filename: test.py
|
|
781
|
+
//// from typing import Any, Protocol
|
|
782
|
+
//// class Source${sourceIsGeneric ? `[T = ${defaultType}]` : ''}:
|
|
783
|
+
//// ${sourceIsGeneric ? 'def put(self, value: T) -> None: ...' : 'def get(self) -> int: ...'}
|
|
784
|
+
//// class Target${sourceIsGeneric ? '' : `[T = ${defaultType}]`}(Protocol):
|
|
785
|
+
//// ${sourceIsGeneric ? 'def put(self, value: int) -> None: ...' : 'def get(self) -> T: ...'}
|
|
786
|
+
//// def check(
|
|
787
|
+
//// good_source: ${sourceIsGeneric ? 'Source[int]' : 'Source'},
|
|
788
|
+
//// bad_source: ${sourceIsGeneric ? 'Source[str]' : 'Source'},
|
|
789
|
+
//// good_target: ${sourceIsGeneric ? 'Target' : 'Target[int]'},
|
|
790
|
+
//// bad_target: ${sourceIsGeneric ? 'Target' : 'Target[str]'},
|
|
791
|
+
//// ):
|
|
792
|
+
//// /*good_source*/good_source
|
|
793
|
+
//// /*bad_source*/bad_source
|
|
794
|
+
//// /*good_target*/good_target
|
|
795
|
+
//// /*bad_target*/bad_target
|
|
796
|
+
`).state;
|
|
797
|
+
const evaluator = state.program.evaluator;
|
|
798
|
+
const typeAt = (marker) => {
|
|
799
|
+
const node = (0, testState_1.getNodeAtMarker)(state, marker);
|
|
800
|
+
assert.strictEqual(node.nodeType, 38 /* ParseNodeType.Name */);
|
|
801
|
+
const type = evaluator.getTypeOfExpression(node).type;
|
|
802
|
+
assert.ok((0, types_1.isClassInstance)(type));
|
|
803
|
+
return type;
|
|
804
|
+
};
|
|
805
|
+
const goodSource = typeAt('good_source');
|
|
806
|
+
const badSource = typeAt('bad_source');
|
|
807
|
+
const goodTarget = types_1.ClassType.cloneAsInstantiable(typeAt('good_target'));
|
|
808
|
+
const badTarget = types_1.ClassType.cloneAsInstantiable(typeAt('bad_target'));
|
|
809
|
+
const assign = (target, source) => (0, protocols_1.assignClassToProtocol)(evaluator, target, source, diagnostics ? new diagnostic_1.DiagnosticAddendum() : undefined, undefined, 0 /* AssignTypeFlags.Default */, 0);
|
|
810
|
+
if (positiveFirst) {
|
|
811
|
+
assert.strictEqual(assign(goodTarget, goodSource), true);
|
|
812
|
+
}
|
|
813
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
814
|
+
assert.strictEqual(assign(badTarget, badSource), false);
|
|
815
|
+
assert.strictEqual(assign(goodTarget, goodSource), true);
|
|
816
|
+
}
|
|
817
|
+
if (!sourceIsGeneric) {
|
|
818
|
+
const typeParam = goodTarget.shared.typeParams[0];
|
|
819
|
+
const genericTarget = types_1.ClassType.specialize(goodTarget, [typeParam]);
|
|
820
|
+
const constraints = new constraintTracker_1.ConstraintTracker();
|
|
821
|
+
assert.strictEqual((0, protocols_1.assignClassToProtocol)(evaluator, genericTarget, goodSource, undefined, constraints, 0 /* AssignTypeFlags.Default */, 0), true);
|
|
822
|
+
assert.strictEqual(evaluator.printType(evaluator.solveAndApplyConstraints(typeParam, constraints)), 'int');
|
|
823
|
+
}
|
|
824
|
+
});
|
|
718
825
|
test('ProtocolExplicit1', () => {
|
|
719
826
|
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['protocolExplicit1.py']);
|
|
720
827
|
TestUtils.validateResults(analysisResults, 5);
|
|
@@ -798,10 +905,31 @@ ${path === 'recursiveReturn'
|
|
|
798
905
|
const marker = state.getMarkerByName('error');
|
|
799
906
|
const line = file.content.slice(0, marker.position).split('\n').length - 1;
|
|
800
907
|
assert.strictEqual(diagnostic.range.start.line, line);
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
908
|
+
const callable = (name) => `(${prefix}x: int${name === 'optional' ? ' = 0' : ''}${suffix}) -> None`;
|
|
909
|
+
const source = `${recursive ? 'B' : 'Source'}[${callable(first)}, ${callable(second)}]`;
|
|
910
|
+
const destination = recursive ? 'A[() -> None]' : 'Dest';
|
|
911
|
+
const header = path === 'recursiveArgument'
|
|
912
|
+
? `Argument of type "${source}" cannot be assigned to parameter "result" of type "${destination}" in function "consume"`
|
|
913
|
+
: `Type "${source}" is not assignable to return type "${destination}"`;
|
|
914
|
+
const indent = '\u00a0\u00a0';
|
|
915
|
+
const entry = path === 'cache'
|
|
916
|
+
? [`${indent}"${first === 'required' ? 'first' : 'second'}" is an incompatible type`]
|
|
917
|
+
: first === 'optional'
|
|
918
|
+
? [`${indent}"next" is an incompatible type`]
|
|
919
|
+
: [];
|
|
920
|
+
const depth = entry.length + 1;
|
|
921
|
+
assert.strictEqual(diagnostic.message, [
|
|
922
|
+
header,
|
|
923
|
+
...entry,
|
|
924
|
+
`${indent.repeat(depth)}"value" is an incompatible type`,
|
|
925
|
+
`${indent.repeat(depth + 1)}Type "${callable('required')}" is not assignable to type "() -> None"`,
|
|
926
|
+
...(kind === 'positionalOnly'
|
|
927
|
+
? [
|
|
928
|
+
`${indent.repeat(depth + 2)}Position-only parameter mismatch; expected 0 but received 1`,
|
|
929
|
+
`${indent.repeat(depth + 2)}Function accepts too many positional parameters; expected 0 but received 1`,
|
|
930
|
+
]
|
|
931
|
+
: [`${indent.repeat(depth + 2)}Extra parameter "x"`]),
|
|
932
|
+
].join('\n'));
|
|
805
933
|
}
|
|
806
934
|
});
|
|
807
935
|
test.each([
|
|
@@ -852,7 +980,15 @@ test.each([
|
|
|
852
980
|
const marker = state.getMarkerByName('error');
|
|
853
981
|
const line = file.content.slice(0, marker.position).split('\n').length - 1;
|
|
854
982
|
assert.strictEqual(diagnostic.range.start.line, line);
|
|
855
|
-
|
|
983
|
+
const callable = (name) => `(x: int${name === 'optional' ? ' = 0' : ''}) -> int`;
|
|
984
|
+
const indent = '\u00a0\u00a0';
|
|
985
|
+
assert.strictEqual(diagnostic.message, [
|
|
986
|
+
`Type "Source[${callable(first)}, ${callable(second)}]" is not assignable to return type "Dest"`,
|
|
987
|
+
`${indent}"${first === 'required' ? 'first' : 'second'}" is an incompatible type`,
|
|
988
|
+
`${indent.repeat(2)}"value" is an incompatible type`,
|
|
989
|
+
`${indent.repeat(3)}Type "(x: int) -> int" is not assignable to type "() -> int"`,
|
|
990
|
+
`${indent.repeat(4)}Extra parameter "x"`,
|
|
991
|
+
].join('\n'));
|
|
856
992
|
}
|
|
857
993
|
});
|
|
858
994
|
test('TypedDictNestedSiblingDiagnostics', () => {
|
|
@@ -892,9 +1028,18 @@ ${classes}
|
|
|
892
1028
|
const diagnostics = new diagnostic_1.DiagnosticAddendum();
|
|
893
1029
|
assert.strictEqual(evaluator.assignType(aType, bType, diagnostics), false);
|
|
894
1030
|
const rendered = diagnostics.getString(undefined, 1000);
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1031
|
+
const indent = '\u00a0\u00a0';
|
|
1032
|
+
assert.strictEqual(rendered, [
|
|
1033
|
+
'',
|
|
1034
|
+
`${indent}"outer" is an incompatible type`,
|
|
1035
|
+
`${indent.repeat(2)}"inside" is an incompatible type`,
|
|
1036
|
+
`${indent.repeat(3)}"first" is an incompatible type`,
|
|
1037
|
+
`${indent.repeat(4)}"value" is an incompatible type`,
|
|
1038
|
+
`${indent.repeat(5)}"str" is not assignable to "int"`,
|
|
1039
|
+
`${indent.repeat(3)}"second" is an incompatible type`,
|
|
1040
|
+
`${indent.repeat(4)}"value" is an incompatible type`,
|
|
1041
|
+
`${indent.repeat(5)}"str" is not assignable to "int"`,
|
|
1042
|
+
].join('\n'));
|
|
898
1043
|
});
|
|
899
1044
|
test.each([64, 65].flatMap((width) => [false, true].map((hotFirst) => ({ width, hotFirst }))))('TypedDictDestinationWorkingSet width=$width hotFirst=$hotFirst', ({ width, hotFirst }) => {
|
|
900
1045
|
const layers = 4;
|
|
@@ -955,11 +1100,41 @@ test('TypedDictRecursive2', () => {
|
|
|
955
1100
|
configOptions.defaultPythonVersion = pythonVersion_1.pythonVersion3_13;
|
|
956
1101
|
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['typedDictRecursive2.py'], configOptions);
|
|
957
1102
|
TestUtils.validateResults(analysisResults, 5);
|
|
958
|
-
const
|
|
959
|
-
assert.
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1103
|
+
const indent = '\u00a0\u00a0';
|
|
1104
|
+
assert.deepStrictEqual(analysisResults[0].errors.map((diagnostic) => diagnostic.message), [
|
|
1105
|
+
[
|
|
1106
|
+
'Type "ReadOnlyStr" is not assignable to declared type "ReadOnlyInt"',
|
|
1107
|
+
`${indent}"value" is an incompatible type`,
|
|
1108
|
+
`${indent.repeat(2)}"str" is not assignable to "int"`,
|
|
1109
|
+
].join('\n'),
|
|
1110
|
+
[
|
|
1111
|
+
'Type "StrParent" is not assignable to declared type "IntParent"',
|
|
1112
|
+
`${indent}"value" is an incompatible type`,
|
|
1113
|
+
`${indent.repeat(2)}"str" is not assignable to "int"`,
|
|
1114
|
+
].join('\n'),
|
|
1115
|
+
[
|
|
1116
|
+
'Type "StrChild" is not assignable to declared type "IntChild"',
|
|
1117
|
+
`${indent}"parent" is an incompatible type`,
|
|
1118
|
+
`${indent.repeat(2)}"value" is an incompatible type`,
|
|
1119
|
+
`${indent.repeat(3)}"str" is not assignable to "int"`,
|
|
1120
|
+
].join('\n'),
|
|
1121
|
+
[
|
|
1122
|
+
'Type "StrWrapper" is not assignable to declared type "IntWrapper"',
|
|
1123
|
+
`${indent}"parent" is an incompatible type`,
|
|
1124
|
+
`${indent.repeat(2)}"value" is an incompatible type`,
|
|
1125
|
+
`${indent.repeat(3)}"str" is not assignable to "int"`,
|
|
1126
|
+
`${indent}"child" is an incompatible type`,
|
|
1127
|
+
`${indent.repeat(2)}"parent" is an incompatible type`,
|
|
1128
|
+
`${indent.repeat(3)}"value" is an incompatible type`,
|
|
1129
|
+
`${indent.repeat(4)}"str" is not assignable to "int"`,
|
|
1130
|
+
`${indent}"again" is an incompatible type`,
|
|
1131
|
+
].join('\n'),
|
|
1132
|
+
[
|
|
1133
|
+
'Type "GenericB[str]" is not assignable to declared type "GenericA[int]"',
|
|
1134
|
+
`${indent}"value" is an incompatible type`,
|
|
1135
|
+
`${indent.repeat(2)}"str" is not assignable to "int"`,
|
|
1136
|
+
].join('\n'),
|
|
1137
|
+
]);
|
|
963
1138
|
});
|
|
964
1139
|
test('TypedDictRecursive3', () => {
|
|
965
1140
|
const configOptions = new configOptions_1.ConfigOptions(uri_1.Uri.empty());
|
|
@@ -1009,7 +1184,13 @@ ${chains}
|
|
|
1009
1184
|
assert.strictEqual(evaluator.assignType(aType, bType), false);
|
|
1010
1185
|
const diagnostics = new diagnostic_1.DiagnosticAddendum();
|
|
1011
1186
|
assert.strictEqual(evaluator.assignType(aType, bType, diagnostics), false);
|
|
1012
|
-
|
|
1187
|
+
const indent = '\u00a0\u00a0';
|
|
1188
|
+
assert.strictEqual(diagnostics.getString(), [
|
|
1189
|
+
'',
|
|
1190
|
+
`${indent}"shallow" is an incompatible type`,
|
|
1191
|
+
`${indent.repeat(2)}"value" is an incompatible type`,
|
|
1192
|
+
`${indent.repeat(3)}"str" is not assignable to "int"`,
|
|
1193
|
+
].join('\n'));
|
|
1013
1194
|
});
|
|
1014
1195
|
test.each([true, false])('TypedDictRecursiveSharedGraph compatible=%s', (compatible) => {
|
|
1015
1196
|
const width = compatible ? 64 : 16;
|
|
@@ -1054,7 +1235,19 @@ ${classes}
|
|
|
1054
1235
|
if (!compatible) {
|
|
1055
1236
|
const diagnostics = new diagnostic_1.DiagnosticAddendum();
|
|
1056
1237
|
assert.strictEqual(evaluator.assignType(aType, bType, diagnostics), false);
|
|
1057
|
-
|
|
1238
|
+
const indent = '\u00a0\u00a0';
|
|
1239
|
+
// Assert the complete 1000-line rendering, including its line-budget boundary:
|
|
1240
|
+
// 15 full outer fields (65 lines each) and a final field with 6 children (25 lines).
|
|
1241
|
+
const expectedLines = Array.from({ length: 16 }, (_, outer) => [
|
|
1242
|
+
`${indent}"field${outer}" is an incompatible type`,
|
|
1243
|
+
...Array.from({ length: outer === 15 ? 6 : 16 }, (_, inner) => [
|
|
1244
|
+
`${indent.repeat(2)}"field${inner}" is an incompatible type`,
|
|
1245
|
+
`${indent.repeat(3)}"field0" is an incompatible type`,
|
|
1246
|
+
`${indent.repeat(4)}"value" is an incompatible type`,
|
|
1247
|
+
`${indent.repeat(5)}"str" is not assignable to "int"`,
|
|
1248
|
+
]).flat(),
|
|
1249
|
+
]).flat();
|
|
1250
|
+
assert.strictEqual(diagnostics.getString(undefined, 1000), ['', ...expectedLines].join('\n'));
|
|
1058
1251
|
}
|
|
1059
1252
|
}
|
|
1060
1253
|
finally {
|
|
@@ -1110,7 +1303,19 @@ ${fields('B')}
|
|
|
1110
1303
|
const diagnostics = new diagnostic_1.DiagnosticAddendum();
|
|
1111
1304
|
assert.strictEqual(evaluator.assignType(aType, bType, diagnostics, constraints), expectedCompatibility);
|
|
1112
1305
|
if (!expectedCompatibility) {
|
|
1113
|
-
|
|
1306
|
+
const indent = '\u00a0\u00a0';
|
|
1307
|
+
const expectedLines = Array.from({ length: 56 }, (_, index) => [
|
|
1308
|
+
`${indent}"rel${index}" is an incompatible type`,
|
|
1309
|
+
`${indent.repeat(2)}Type "bool | BArgs" is not assignable to type "bool | AArgs"`,
|
|
1310
|
+
`${indent.repeat(3)}Type "BArgs" is not assignable to type "bool | AArgs"`,
|
|
1311
|
+
`${indent.repeat(4)}"BArgs" is not assignable to "bool"`,
|
|
1312
|
+
]).flat();
|
|
1313
|
+
assert.strictEqual(diagnostics.getString(undefined, 1000), [
|
|
1314
|
+
'',
|
|
1315
|
+
...expectedLines,
|
|
1316
|
+
`${indent}"value" is an incompatible type`,
|
|
1317
|
+
`${indent.repeat(2)}"str" is not assignable to "int"`,
|
|
1318
|
+
].join('\n'));
|
|
1114
1319
|
}
|
|
1115
1320
|
}
|
|
1116
1321
|
finally {
|
|
@@ -1385,6 +1590,28 @@ test('Annotated2', () => {
|
|
|
1385
1590
|
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['annotated2.py']);
|
|
1386
1591
|
TestUtils.validateResults(analysisResults, 0);
|
|
1387
1592
|
});
|
|
1593
|
+
test('Annotated10', () => {
|
|
1594
|
+
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['annotated10.py']);
|
|
1595
|
+
TestUtils.validateResults(analysisResults, 2);
|
|
1596
|
+
});
|
|
1597
|
+
test('Annotated11', () => {
|
|
1598
|
+
const configOptions = new configOptions_1.ConfigOptions(uri_1.Uri.empty());
|
|
1599
|
+
configOptions.defaultPythonVersion = pythonVersion_1.pythonVersion3_13;
|
|
1600
|
+
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['annotated11.py'], configOptions);
|
|
1601
|
+
TestUtils.validateResults(analysisResults, 10);
|
|
1602
|
+
});
|
|
1603
|
+
test('Annotated12', () => {
|
|
1604
|
+
const configOptions = new configOptions_1.ConfigOptions(uri_1.Uri.empty());
|
|
1605
|
+
configOptions.defaultPythonVersion = pythonVersion_1.pythonVersion3_13;
|
|
1606
|
+
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['annotated12.py'], configOptions);
|
|
1607
|
+
TestUtils.validateResults(analysisResults, 12);
|
|
1608
|
+
const errors = analysisResults[0].errors;
|
|
1609
|
+
assert.deepStrictEqual(errors.map((diagnostic) => [diagnostic.range.start.line + 1, diagnostic.getRule()]), [30, 31, 32, 38, 39, 40, 42, 43, 44, 72, 86, 87].map((line) => [
|
|
1610
|
+
line,
|
|
1611
|
+
diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue,
|
|
1612
|
+
]));
|
|
1613
|
+
assert.match(errors.find((diagnostic) => diagnostic.range.start.line + 1 === 86).message, /__get__/);
|
|
1614
|
+
});
|
|
1388
1615
|
test('Circular1', () => {
|
|
1389
1616
|
const configOptions = new configOptions_1.ConfigOptions(uri_1.Uri.empty());
|
|
1390
1617
|
// This test requires 3.13 or older because 3.14 uses deferred
|