@zzzen/pyright-internal 1.2.0-dev.20240901 → 1.2.0-dev.20240915
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/analysis.d.ts +1 -0
- package/dist/analyzer/analysis.js +2 -0
- package/dist/analyzer/analysis.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +6 -2
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +14 -8
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/cacheManager.d.ts +2 -2
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.js +53 -192
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +7 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -2
- package/dist/analyzer/constraintSolver.js +2 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +7 -1
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +6 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/namedTuples.js +4 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +5 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +1 -1
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +2 -3
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +1 -2
- package/dist/analyzer/protocols.js +5 -8
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.d.ts +1 -1
- package/dist/analyzer/service.d.ts +3 -1
- package/dist/analyzer/service.js +50 -33
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +10 -5
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +1 -2
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +599 -181
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +33 -6
- package/dist/analyzer/typeEvaluatorTypes.js +66 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +3 -12
- package/dist/analyzer/typeGuards.js +286 -461
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +12 -1
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -17
- package/dist/analyzer/typeUtils.js +61 -60
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +1 -2
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +9 -4
- package/dist/analyzer/types.js +80 -26
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +23 -16
- package/dist/backgroundAnalysisBase.js +64 -35
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.js +9 -0
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +1 -1
- package/dist/common/uri/uriUtils.d.ts +1 -1
- package/dist/common/uri/uriUtils.js +6 -1
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +2 -2
- package/dist/languageServerBase.js +1 -3
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +6 -1
- package/dist/languageService/analyzerServiceExecutor.js +7 -6
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +2 -1
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +12 -12
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +6 -6
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +9 -9
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.d.ts +5 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +12 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +1 -0
- package/dist/languageService/hoverProvider.js +30 -3
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +2 -2
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +2 -2
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +10 -0
- package/dist/localization/localize.js +4 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +155 -153
- package/dist/localization/package.nls.de.json +128 -126
- package/dist/localization/package.nls.en-us.json +1632 -404
- package/dist/localization/package.nls.es.json +151 -149
- package/dist/localization/package.nls.fr.json +129 -127
- package/dist/localization/package.nls.it.json +143 -141
- package/dist/localization/package.nls.ja.json +142 -140
- package/dist/localization/package.nls.ko.json +155 -153
- package/dist/localization/package.nls.pl.json +178 -176
- package/dist/localization/package.nls.pt-br.json +139 -137
- package/dist/localization/package.nls.qps-ploc.json +392 -390
- package/dist/localization/package.nls.ru.json +170 -168
- package/dist/localization/package.nls.tr.json +153 -151
- package/dist/localization/package.nls.zh-cn.json +149 -147
- package/dist/localization/package.nls.zh-tw.json +133 -131
- package/dist/parser/parseNodes.d.ts +2 -3
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +6 -20
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/checker.test.js +14 -1
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/envVarUtils.test.js +0 -3
- package/dist/tests/envVarUtils.test.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +0 -3
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -5
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.d.ts +1 -0
- package/dist/tests/harness/fourslash/testStateUtils.js +5 -0
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
- package/dist/tests/harness/vfs/filesystem.js +6 -3
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +1 -1
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/service.test.js +31 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +5 -1
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +13 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +5 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +6 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +5 -1
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +1 -1
- package/dist/tests/typeEvaluator8.test.js +40 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +2 -20
- package/dist/workspaceFactory.js +26 -64
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
package/dist/analyzer/checker.js
CHANGED
@@ -412,7 +412,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
412
412
|
}
|
413
413
|
}
|
414
414
|
this._scopedNodes.push(node);
|
415
|
-
if (functionTypeResult &&
|
415
|
+
if (functionTypeResult &&
|
416
|
+
(0, types_1.isOverloaded)(functionTypeResult.decoratedType) &&
|
417
|
+
functionTypeResult.functionType.priv.overloaded) {
|
416
418
|
// If this is the implementation for the overloaded function, skip
|
417
419
|
// overload consistency checks.
|
418
420
|
if (types_1.OverloadedType.getImplementation(functionTypeResult.decoratedType) !== functionTypeResult.functionType) {
|
@@ -672,34 +674,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
672
674
|
return true;
|
673
675
|
}
|
674
676
|
visitRaise(node) {
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
if (exceptionType && baseExceptionType && (0, types_1.isInstantiableClass)(baseExceptionType)) {
|
681
|
-
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
682
|
-
(0, typeUtils_1.doForEachSubtype)(exceptionType, (subtype) => {
|
683
|
-
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
684
|
-
if (!(0, types_1.isAnyOrUnknown)(subtype) && !(0, typeUtils_1.isNoneInstance)(subtype)) {
|
685
|
-
if ((0, types_1.isClass)(subtype)) {
|
686
|
-
if (!(0, typeUtils_1.derivesFromClassRecursive)(subtype, baseExceptionType, /* ignoreUnknown */ false)) {
|
687
|
-
diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
|
688
|
-
type: this._evaluator.printType(subtype),
|
689
|
-
}));
|
690
|
-
}
|
691
|
-
}
|
692
|
-
else {
|
693
|
-
diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
|
694
|
-
type: this._evaluator.printType(subtype),
|
695
|
-
}));
|
696
|
-
}
|
697
|
-
}
|
698
|
-
});
|
699
|
-
if (!diagAddendum.isEmpty()) {
|
700
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedExceptionObj() + diagAddendum.getString(), node.d.valueExpression);
|
701
|
-
}
|
702
|
-
}
|
677
|
+
if (node.d.expr) {
|
678
|
+
this._evaluator.verifyRaiseExceptionType(node.d.expr);
|
679
|
+
}
|
680
|
+
if (node.d.fromExpr) {
|
681
|
+
this._evaluator.verifyRaiseExceptionType(node.d.fromExpr);
|
703
682
|
}
|
704
683
|
return true;
|
705
684
|
}
|
@@ -1009,11 +988,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1009
988
|
return true;
|
1010
989
|
}
|
1011
990
|
visitImportFromAs(node) {
|
1012
|
-
var _a, _b;
|
991
|
+
var _a, _b, _c;
|
1013
992
|
if (this._fileInfo.isStubFile) {
|
1014
993
|
return false;
|
1015
994
|
}
|
1016
|
-
const decls = this._evaluator.
|
995
|
+
const decls = (_a = this._evaluator.getDeclInfoForNameNode(node.d.name)) === null || _a === void 0 ? void 0 : _a.decls;
|
1017
996
|
if (!decls) {
|
1018
997
|
return false;
|
1019
998
|
}
|
@@ -1035,14 +1014,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1035
1014
|
break;
|
1036
1015
|
}
|
1037
1016
|
let isImportFromTyping = false;
|
1038
|
-
if (((
|
1017
|
+
if (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 25 /* ParseNodeType.ImportFrom */) {
|
1039
1018
|
if (node.parent.d.module.d.leadingDots === 0 && node.parent.d.module.d.nameParts.length === 1) {
|
1040
1019
|
if (node.parent.d.module.d.nameParts[0].d.value === 'typing') {
|
1041
1020
|
isImportFromTyping = true;
|
1042
1021
|
}
|
1043
1022
|
}
|
1044
1023
|
}
|
1045
|
-
const type = this._evaluator.getType((
|
1024
|
+
const type = this._evaluator.getType((_c = node.d.alias) !== null && _c !== void 0 ? _c : node.d.name);
|
1046
1025
|
this._reportDeprecatedUseForType(node.d.name, type, isImportFromTyping);
|
1047
1026
|
return false;
|
1048
1027
|
}
|
@@ -1851,7 +1830,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1851
1830
|
// earlier overload. Typeshed stubs contain type: ignore comments on these
|
1852
1831
|
// lines, so it is important for us to report them in the same manner.
|
1853
1832
|
_findNodeForOverload(functionNode, overloadType) {
|
1854
|
-
|
1833
|
+
var _a;
|
1834
|
+
const decls = (_a = this._evaluator.getDeclInfoForNameNode(functionNode.d.name)) === null || _a === void 0 ? void 0 : _a.decls;
|
1855
1835
|
if (!decls) {
|
1856
1836
|
return undefined;
|
1857
1837
|
}
|
@@ -2739,161 +2719,40 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2739
2719
|
}
|
2740
2720
|
curNode = curNode.parent;
|
2741
2721
|
}
|
2742
|
-
|
2743
|
-
|
2744
|
-
// are used.
|
2745
|
-
const nonstandardClassTypes = [
|
2746
|
-
'FunctionType',
|
2747
|
-
'LambdaType',
|
2748
|
-
'BuiltinFunctionType',
|
2749
|
-
'BuiltinMethodType',
|
2750
|
-
'type',
|
2751
|
-
'Type',
|
2752
|
-
];
|
2753
|
-
const classTypeList = [];
|
2754
|
-
let arg1IncludesSubclasses = false;
|
2755
|
-
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2756
|
-
if ((0, types_1.isClass)(arg1Subtype)) {
|
2757
|
-
if (types_1.TypeBase.isInstantiable(arg1Subtype)) {
|
2758
|
-
if (arg1Subtype.priv.literalValue === undefined) {
|
2759
|
-
classTypeList.push(arg1Subtype);
|
2760
|
-
if (types_1.ClassType.isBuiltIn(arg1Subtype) &&
|
2761
|
-
nonstandardClassTypes.some((name) => name === arg1Subtype.shared.name)) {
|
2762
|
-
isValidType = false;
|
2763
|
-
}
|
2764
|
-
if (arg1Subtype.priv.includeSubclasses) {
|
2765
|
-
arg1IncludesSubclasses = true;
|
2766
|
-
}
|
2767
|
-
}
|
2768
|
-
if (arg0Type) {
|
2769
|
-
this._validateUnsafeProtocolOverlap(node.d.args[0].d.valueExpr, (0, typeUtils_1.convertToInstance)(arg1Subtype), isInstanceCheck ? arg0Type : (0, typeUtils_1.convertToInstance)(arg0Type));
|
2770
|
-
}
|
2771
|
-
}
|
2772
|
-
else {
|
2773
|
-
// The isinstance and issubclass call supports a variation where the second
|
2774
|
-
// parameter is a tuple of classes.
|
2775
|
-
if ((0, typeUtils_1.isTupleClass)(arg1Subtype)) {
|
2776
|
-
if (arg1Subtype.priv.tupleTypeArgs) {
|
2777
|
-
arg1Subtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2778
|
-
if ((0, types_1.isInstantiableClass)(typeArg.type)) {
|
2779
|
-
classTypeList.push(typeArg.type);
|
2780
|
-
if (typeArg.type.priv.includeSubclasses) {
|
2781
|
-
arg1IncludesSubclasses = true;
|
2782
|
-
}
|
2783
|
-
if (arg0Type) {
|
2784
|
-
this._validateUnsafeProtocolOverlap(node.d.args[0].d.valueExpr, (0, typeUtils_1.convertToInstance)(typeArg.type), isInstanceCheck ? arg0Type : (0, typeUtils_1.convertToInstance)(arg0Type));
|
2785
|
-
}
|
2786
|
-
}
|
2787
|
-
else {
|
2788
|
-
isValidType = false;
|
2789
|
-
}
|
2790
|
-
});
|
2791
|
-
}
|
2792
|
-
}
|
2793
|
-
else {
|
2794
|
-
if (arg1Subtype.priv.includeSubclasses) {
|
2795
|
-
arg1IncludesSubclasses = true;
|
2796
|
-
}
|
2797
|
-
}
|
2798
|
-
if (types_1.ClassType.isBuiltIn(arg1Subtype) &&
|
2799
|
-
nonstandardClassTypes.some((name) => name === arg1Subtype.shared.name)) {
|
2800
|
-
isValidType = false;
|
2801
|
-
}
|
2802
|
-
}
|
2803
|
-
}
|
2804
|
-
else {
|
2805
|
-
isValidType = false;
|
2806
|
-
}
|
2807
|
-
});
|
2808
|
-
if (!isValidType) {
|
2809
|
-
return;
|
2810
|
-
}
|
2811
|
-
if ((0, typeUtils_1.derivesFromAnyOrUnknown)(arg0Type)) {
|
2722
|
+
const classTypeList = (0, typeGuards_1.getIsInstanceClassTypes)(this._evaluator, arg1Type);
|
2723
|
+
if (!classTypeList) {
|
2812
2724
|
return;
|
2813
2725
|
}
|
2814
|
-
|
2815
|
-
|
2816
|
-
|
2817
|
-
|
2818
|
-
const filteredTypes = [];
|
2819
|
-
for (const filterType of classTypeList) {
|
2820
|
-
const filterIsSuperclass = (0, typeGuards_1.isIsinstanceFilterSuperclass)(this._evaluator, varType, varType, filterType, filterType, isInstanceCheck);
|
2821
|
-
const filterIsSubclass = (0, typeGuards_1.isIsinstanceFilterSubclass)(this._evaluator, varType, filterType, isInstanceCheck);
|
2822
|
-
// Normally, a class should never be both a subclass and a
|
2823
|
-
// superclass. However, this can happen if one of the classes
|
2824
|
-
// derives from an unknown type. In this case, we'll add an
|
2825
|
-
// unknown type into the filtered type list to avoid any
|
2826
|
-
// false positives.
|
2827
|
-
const isClassRelationshipIndeterminate = filterIsSuperclass && filterIsSubclass && !types_1.ClassType.isSameGenericClass(varType, filterType);
|
2828
|
-
if (isClassRelationshipIndeterminate) {
|
2829
|
-
filteredTypes.push(types_1.UnknownType.create());
|
2830
|
-
}
|
2831
|
-
else if (filterIsSuperclass) {
|
2832
|
-
// If the variable type is a subclass of the isinstance
|
2833
|
-
// filter, we haven't learned anything new about the
|
2834
|
-
// variable type.
|
2835
|
-
filteredTypes.push(varType);
|
2836
|
-
}
|
2837
|
-
else if (filterIsSubclass) {
|
2838
|
-
// If the variable type is a superclass of the isinstance
|
2839
|
-
// filter, we can narrow the type to the subclass.
|
2840
|
-
filteredTypes.push(filterType);
|
2841
|
-
}
|
2842
|
-
}
|
2843
|
-
if (!isInstanceCheck) {
|
2844
|
-
return filteredTypes;
|
2845
|
-
}
|
2846
|
-
// Make all instantiable classes into instances before returning them.
|
2847
|
-
return filteredTypes.map((t) => ((0, types_1.isInstantiableClass)(t) ? types_1.ClassType.cloneAsInstance(t) : t));
|
2848
|
-
};
|
2849
|
-
let filteredType;
|
2850
|
-
if (isInstanceCheck && (0, types_1.isClassInstance)(arg0Type)) {
|
2851
|
-
const remainingTypes = filterType(types_1.ClassType.cloneAsInstantiable(arg0Type));
|
2852
|
-
filteredType = finalizeFilteredTypeList(remainingTypes);
|
2853
|
-
}
|
2854
|
-
else if (!isInstanceCheck && (0, types_1.isInstantiableClass)(arg0Type)) {
|
2855
|
-
const remainingTypes = filterType(arg0Type);
|
2856
|
-
filteredType = finalizeFilteredTypeList(remainingTypes);
|
2857
|
-
}
|
2858
|
-
else if ((0, types_1.isUnion)(arg0Type)) {
|
2859
|
-
let remainingTypes = [];
|
2860
|
-
let foundAnyType = false;
|
2861
|
-
(0, typeUtils_1.doForEachSubtype)(arg0Type, (subtype) => {
|
2862
|
-
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
2863
|
-
foundAnyType = true;
|
2864
|
-
}
|
2865
|
-
if (isInstanceCheck && (0, types_1.isClassInstance)(subtype)) {
|
2866
|
-
remainingTypes = remainingTypes.concat(filterType(types_1.ClassType.cloneAsInstantiable(subtype)));
|
2867
|
-
}
|
2868
|
-
else if (!isInstanceCheck && (0, types_1.isInstantiableClass)(subtype)) {
|
2869
|
-
remainingTypes = remainingTypes.concat(filterType(subtype));
|
2870
|
-
}
|
2871
|
-
});
|
2872
|
-
filteredType = finalizeFilteredTypeList(remainingTypes);
|
2873
|
-
// If we found an any or unknown type, all bets are off.
|
2874
|
-
if (foundAnyType) {
|
2875
|
-
return;
|
2726
|
+
// Check for unsafe protocol overlaps.
|
2727
|
+
classTypeList.forEach((filterType) => {
|
2728
|
+
if ((0, types_1.isInstantiableClass)(filterType)) {
|
2729
|
+
this._validateUnsafeProtocolOverlap(node.d.args[0].d.valueExpr, (0, typeUtils_1.convertToInstance)(filterType), isInstanceCheck ? arg0Type : (0, typeUtils_1.convertToInstance)(arg0Type));
|
2876
2730
|
}
|
2877
|
-
}
|
2878
|
-
|
2879
|
-
|
2880
|
-
|
2881
|
-
|
2882
|
-
|
2883
|
-
|
2884
|
-
|
2885
|
-
|
2886
|
-
|
2887
|
-
|
2888
|
-
|
2889
|
-
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2731
|
+
});
|
2732
|
+
// Check for unnecessary isinstance or issubclass calls.
|
2733
|
+
if (this._fileInfo.diagnosticRuleSet.reportUnnecessaryIsInstance !== 'none') {
|
2734
|
+
const narrowedTypeNegative = (0, typeGuards_1.narrowTypeForInstanceOrSubclass)(this._evaluator, arg0Type, classTypeList, isInstanceCheck,
|
2735
|
+
/* isTypeIsCheck */ false,
|
2736
|
+
/* isPositiveTest */ false, node);
|
2737
|
+
const narrowedTypePositive = (0, typeGuards_1.narrowTypeForInstanceOrSubclass)(this._evaluator, arg0Type, classTypeList, isInstanceCheck,
|
2738
|
+
/* isTypeIsCheck */ false,
|
2739
|
+
/* isPositiveTest */ true, node);
|
2740
|
+
const isAlwaysTrue = (0, types_1.isNever)(narrowedTypeNegative);
|
2741
|
+
const isNeverTrue = (0, types_1.isNever)(narrowedTypePositive);
|
2742
|
+
if (isAlwaysTrue || isNeverTrue) {
|
2743
|
+
const classType = (0, types_1.combineTypes)(classTypeList.map((t) => (0, typeUtils_1.convertToInstance)(t)));
|
2744
|
+
const messageTemplate = isAlwaysTrue
|
2745
|
+
? isInstanceCheck
|
2746
|
+
? localize_1.LocMessage.unnecessaryIsInstanceAlways()
|
2747
|
+
: localize_1.LocMessage.unnecessaryIsSubclassAlways()
|
2748
|
+
: isInstanceCheck
|
2749
|
+
? localize_1.LocMessage.unnecessaryIsInstanceNever()
|
2750
|
+
: localize_1.LocMessage.unnecessaryIsSubclassNever();
|
2751
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnnecessaryIsInstance, messageTemplate.format({
|
2894
2752
|
testType: this._evaluator.printType(arg0Type),
|
2895
|
-
classType: this._evaluator.printType(
|
2753
|
+
classType: this._evaluator.printType(classType),
|
2896
2754
|
}), node);
|
2755
|
+
}
|
2897
2756
|
}
|
2898
2757
|
}
|
2899
2758
|
_validateUnsafeProtocolOverlap(errorNode, protocol, testType) {
|
@@ -3182,7 +3041,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3182
3041
|
if (pythonVersion_1.PythonVersion.isGreaterOrEqualTo(this._fileInfo.executionEnvironment.pythonVersion, deprecatedForm.version)) {
|
3183
3042
|
if (!deprecatedForm.typingImportOnly || isImportFromTyping) {
|
3184
3043
|
this._reportDeprecatedDiagnostic(node, localize_1.LocMessage.deprecatedType().format({
|
3185
|
-
version:
|
3044
|
+
version: pythonVersion_1.PythonVersion.toString(deprecatedForm.version),
|
3186
3045
|
replacement: deprecatedForm.replacementText,
|
3187
3046
|
}));
|
3188
3047
|
}
|
@@ -3306,7 +3165,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3306
3165
|
}
|
3307
3166
|
}
|
3308
3167
|
_conditionallyReportPrivateUsage(node) {
|
3309
|
-
var _a, _b;
|
3168
|
+
var _a, _b, _c;
|
3310
3169
|
if (this._fileInfo.diagnosticRuleSet.reportPrivateUsage === 'none') {
|
3311
3170
|
return;
|
3312
3171
|
}
|
@@ -3329,8 +3188,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3329
3188
|
// Get the declarations for this name node, but filter out
|
3330
3189
|
// any variable declarations that are bound using nonlocal
|
3331
3190
|
// or global explicit bindings.
|
3332
|
-
const declarations = (_b = this._evaluator
|
3333
|
-
.
|
3191
|
+
const declarations = (_c = (_b = this._evaluator
|
3192
|
+
.getDeclInfoForNameNode(node)) === null || _b === void 0 ? void 0 : _b.decls) === null || _c === void 0 ? void 0 : _c.filter((decl) => decl.type !== 1 /* DeclarationType.Variable */ || !decl.isExplicitBinding);
|
3334
3193
|
let primaryDeclaration = declarations && declarations.length > 0 ? declarations[declarations.length - 1] : undefined;
|
3335
3194
|
if (!primaryDeclaration || primaryDeclaration.node === node) {
|
3336
3195
|
return;
|
@@ -3465,7 +3324,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3465
3324
|
}
|
3466
3325
|
if (isTypeIs) {
|
3467
3326
|
const scopeIds = (0, typeUtils_1.getTypeVarScopeIds)(functionType);
|
3468
|
-
const
|
3327
|
+
const narrowedType = returnType.priv.typeArgs[0];
|
3328
|
+
let typeGuardType = (0, typeUtils_1.makeTypeVarsBound)(narrowedType, scopeIds);
|
3329
|
+
typeGuardType = types_1.TypeBase.cloneWithTypeForm(typeGuardType, typeGuardType);
|
3469
3330
|
// Determine the type of the first parameter.
|
3470
3331
|
const paramIndex = isMethod && !types_1.FunctionType.isStaticMethod(functionType) ? 1 : 0;
|
3471
3332
|
if (paramIndex >= functionType.shared.parameters.length) {
|
@@ -3478,7 +3339,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3478
3339
|
if (returnAnnotation) {
|
3479
3340
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeIsReturnType().format({
|
3480
3341
|
type: this._evaluator.printType(paramType),
|
3481
|
-
returnType: this._evaluator.printType(
|
3342
|
+
returnType: this._evaluator.printType(narrowedType),
|
3482
3343
|
}), returnAnnotation);
|
3483
3344
|
}
|
3484
3345
|
}
|
@@ -3604,7 +3465,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3604
3465
|
className: parentSymbol.classType.shared.name,
|
3605
3466
|
}), decl.node);
|
3606
3467
|
}
|
3607
|
-
else if (types_1.ClassType.
|
3468
|
+
else if (types_1.ClassType.hasNamedTupleEntry(parentSymbol.classType, name) &&
|
3608
3469
|
!SymbolNameUtils.isDunderName(name)) {
|
3609
3470
|
// If the parent class is a named tuple, all instance variables
|
3610
3471
|
// (other than dundered ones) are implicitly final.
|
@@ -3893,7 +3754,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3893
3754
|
// If this is part of a dataclass, a class handled by a dataclass_transform,
|
3894
3755
|
// or a NamedTuple, exempt it because the class variable will be transformed
|
3895
3756
|
// into an instance variable in this case.
|
3896
|
-
if (types_1.ClassType.isDataClass(classType) || types_1.ClassType.
|
3757
|
+
if (types_1.ClassType.isDataClass(classType) || types_1.ClassType.hasNamedTupleEntry(classType, name)) {
|
3897
3758
|
return true;
|
3898
3759
|
}
|
3899
3760
|
// If this is part of a TypedDict, exempt it because the class variables
|