@zzzen/pyright-internal 1.2.0-dev.20231001 → 1.2.0-dev.20231015
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/checker.d.ts +3 -1
- package/dist/analyzer/checker.js +82 -41
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +11 -4
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +208 -151
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/decorators.d.ts +6 -1
- package/dist/analyzer/decorators.js +34 -25
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +2 -1
- package/dist/analyzer/parseTreeUtils.js +21 -2
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/program.js +7 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.d.ts +2 -2
- package/dist/analyzer/properties.js +8 -2
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +102 -149
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scopeUtils.js +3 -2
- package/dist/analyzer/scopeUtils.js.map +1 -1
- package/dist/analyzer/service.js +13 -13
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +21 -7
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfo.d.ts +4 -4
- package/dist/analyzer/sourceFileInfo.js +2 -0
- package/dist/analyzer/sourceFileInfo.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +2 -1
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +2 -1
- package/dist/analyzer/typeEvaluator.js +171 -244
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +10 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +127 -55
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -1
- package/dist/analyzer/typeUtils.js +82 -8
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +4 -1
- package/dist/analyzer/typeVarContext.js +7 -2
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/types.d.ts +5 -2
- package/dist/analyzer/types.js +25 -14
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundThreadBase.js +5 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +9 -5
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +19 -8
- package/dist/common/extensibility.js +6 -7
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +9 -4
- package/dist/common/fileSystem.js +8 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/pathUtils.d.ts +5 -4
- package/dist/common/pathUtils.js +13 -7
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/pythonVersion.d.ts +1 -1
- package/dist/common/pythonVersion.js +1 -1
- package/dist/common/realFileSystem.d.ts +7 -1
- package/dist/common/realFileSystem.js +33 -37
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.d.ts +1 -1
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +5 -3
- package/dist/common/serviceProviderExtensions.js +6 -1
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +6 -2
- package/dist/languageServerBase.js +31 -4
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +1 -1
- package/dist/languageService/callHierarchyProvider.d.ts +0 -1
- package/dist/languageService/callHierarchyProvider.js +33 -16
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -2
- package/dist/languageService/completionProvider.js +20 -23
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +4 -5
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.js +5 -2
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +32 -23
- package/dist/languageService/documentSymbolCollector.js +170 -267
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +1 -5
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/navigationUtils.d.ts +1 -1
- package/dist/languageService/navigationUtils.js +2 -2
- package/dist/languageService/navigationUtils.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +15 -8
- package/dist/languageService/referencesProvider.js +41 -20
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.js +3 -3
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +21 -0
- package/dist/localization/localize.js +7 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +5 -0
- package/dist/localization/package.nls.de.json +5 -0
- package/dist/localization/package.nls.en-us.json +7 -0
- package/dist/localization/package.nls.es.json +5 -0
- package/dist/localization/package.nls.fr.json +5 -0
- package/dist/localization/package.nls.it.json +5 -0
- package/dist/localization/package.nls.ja.json +5 -0
- package/dist/localization/package.nls.ko.json +5 -0
- package/dist/localization/package.nls.pl.json +5 -0
- package/dist/localization/package.nls.pt-br.json +5 -0
- package/dist/localization/package.nls.qps-ploc.json +5 -0
- package/dist/localization/package.nls.ru.json +5 -0
- package/dist/localization/package.nls.tr.json +5 -0
- package/dist/localization/package.nls.zh-cn.json +5 -0
- package/dist/localization/package.nls.zh-tw.json +5 -0
- package/dist/parser/stringTokenUtils.js +9 -5
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +1 -0
- package/dist/parser/tokenizer.js +5 -5
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/pyright.js +2 -1
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +0 -1
- package/dist/pyrightFileSystem.js +0 -3
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -4
- package/dist/readonlyAugmentedFileSystem.js +0 -10
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/checker.test.js +8 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/config.test.js +5 -3
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/documentSymbolCollector.test.js +8 -363
- package/dist/tests/documentSymbolCollector.test.js.map +1 -1
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +56 -10
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +5 -2
- package/dist/tests/harness/fourslash/testState.js +13 -14
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +2 -2
- package/dist/tests/importResolver.test.js +0 -9
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +2 -2
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/testStateUtils.d.ts +3 -0
- package/dist/tests/testStateUtils.js +25 -1
- package/dist/tests/testStateUtils.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 -5
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +12 -4
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +17 -9
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +4 -2
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +2 -1
- package/dist/workspaceFactory.js +3 -1
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.overriddenFunction.fourslash.d.ts +0 -1
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.overriddenFunction.fourslash.js +0 -40
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.overriddenFunction.fourslash.js.map +0 -1
@@ -53,7 +53,7 @@ export interface TypeResult<T extends Type = Type> {
|
|
53
53
|
typeList?: TypeResultWithNode[] | undefined;
|
54
54
|
inlinedTypeDict?: ClassType;
|
55
55
|
typeErrors?: boolean | undefined;
|
56
|
-
classType?: ClassType | UnknownType;
|
56
|
+
classType?: ClassType | UnknownType | AnyType;
|
57
57
|
isEmptyTupleShorthand?: boolean | undefined;
|
58
58
|
expectedTypeDiagAddendum?: DiagnosticAddendum | undefined;
|
59
59
|
isAsymmetricAccessor?: boolean;
|
@@ -61,10 +61,16 @@ export interface TypeResult<T extends Type = Type> {
|
|
61
61
|
isNotRequired?: boolean;
|
62
62
|
isReadOnly?: boolean;
|
63
63
|
overloadsUsedForCall?: FunctionType[];
|
64
|
+
memberAccessDeprecationInfo?: MemberAccessDeprecationInfo;
|
64
65
|
}
|
65
66
|
export interface TypeResultWithNode extends TypeResult {
|
66
67
|
node: ParseNode;
|
67
68
|
}
|
69
|
+
export interface MemberAccessDeprecationInfo {
|
70
|
+
accessType: 'property' | 'descriptor';
|
71
|
+
accessMethod: 'get' | 'set' | 'del';
|
72
|
+
deprecationMessage: string;
|
73
|
+
}
|
68
74
|
export interface EvaluatorUsage {
|
69
75
|
method: 'get' | 'set' | 'del';
|
70
76
|
setType?: TypeResult | undefined;
|
@@ -180,10 +186,12 @@ export interface ClassMemberLookup {
|
|
180
186
|
symbol: Symbol | undefined;
|
181
187
|
type: Type;
|
182
188
|
isTypeIncomplete: boolean;
|
189
|
+
isSetTypeError: boolean;
|
183
190
|
isClassMember: boolean;
|
184
|
-
classType?: ClassType | UnknownType;
|
191
|
+
classType?: ClassType | UnknownType | AnyType;
|
185
192
|
isClassVar: boolean;
|
186
193
|
isAsymmetricAccessor: boolean;
|
194
|
+
memberAccessDeprecationInfo?: MemberAccessDeprecationInfo;
|
187
195
|
}
|
188
196
|
export interface PrintTypeOptions {
|
189
197
|
expandTypeAlias?: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"typeEvaluatorTypes.js","sourceRoot":"","sources":["../../../src/analyzer/typeEvaluatorTypes.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA8CH,gEAAgE;AAChE,kDAAkD;AACrC,QAAA,0BAA0B,GAAG,EAAE,CAAC;AAE7C,IAAkB,cAkGjB;AAlGD,WAAkB,cAAc;IAC5B,mDAAQ,CAAA;IAER,uDAAuD;IACvD,mFAA6B,CAAA;IAE7B,0DAA0D;IAC1D,gEAAgE;IAChE,SAAS;IACT,yEAAwB,CAAA;IAExB,yDAAyD;IACzD,uFAA+B,CAAA;IAE/B,kCAAkC;IAClC,iGAAoC,CAAA;IAEpC,0CAA0C;IAC1C,sEAAsB,CAAA;IAEtB,6CAA6C;IAC7C,8EAA0B,CAAA;IAE1B,gDAAgD;IAChD,oFAA6B,CAAA;IAE7B,2DAA2D;IAC3D,4BAA4B;IAC5B,+FAAkC,CAAA;IAElC,gEAAgE;IAChE,6DAA6D;IAC7D,qBAAqB;IACrB,2FAAgC,CAAA;IAEhC,qEAAqE;IACrE,qFAA6B,CAAA;IAE7B,2DAA2D;IAC3D,gDAAgD;IAChD,wFAA+B,CAAA;IAE/B,8DAA8D;IAC9D,0BAA0B;IAC1B,oGAA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/D,+EAAwB,CAAA;IAExB,wDAAwD;IACxD,uFAA4B,CAAA;IAE5B,+DAA+D;IAC/D,8FAA+B,CAAA;IAE/B,2DAA2D;IAC3D,0DAA0D;IAC1D,oCAAoC;IACpC,4GAAsC,CAAA;IAEtC,+DAA+D;IAC/D,gEAAgE;IAChE,yBAAyB;IACzB,4FAA8B,CAAA;IAE9B,4DAA4D;IAC5D,wDAAwD;IACxD,8DAA8D;IAC9D,4BAA4B;IAC5B,yGAAoC,CAAA;IAEpC,sDAAsD;IACtD,qFAA0B,CAAA;IAE1B,sDAAsD;IACtD,qFAA0B,CAAA;AAC9B,CAAC,EA3CiB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QA2ClC"}
|
@@ -7,7 +7,7 @@ export interface TypeNarrowingResult {
|
|
7
7
|
}
|
8
8
|
export declare type TypeNarrowingCallback = (type: Type) => TypeNarrowingResult | undefined;
|
9
9
|
export declare function getTypeNarrowingCallback(evaluator: TypeEvaluator, reference: ExpressionNode, testExpression: ExpressionNode, isPositiveTest: boolean, recursionCount?: number): TypeNarrowingCallback | undefined;
|
10
|
-
export declare function isIsinstanceFilterSuperclass(evaluator: TypeEvaluator, varType: ClassType, filterType: Type, concreteFilterType: ClassType, isInstanceCheck: boolean): boolean;
|
10
|
+
export declare function isIsinstanceFilterSuperclass(evaluator: TypeEvaluator, varType: Type, concreteVarType: ClassType, filterType: Type, concreteFilterType: ClassType, isInstanceCheck: boolean): boolean;
|
11
11
|
export declare function isIsinstanceFilterSubclass(evaluator: TypeEvaluator, varType: ClassType, concreteFilterType: ClassType, isInstanceCheck: boolean): boolean;
|
12
12
|
export declare function getElementTypeForContainerNarrowing(containerType: Type): Type | undefined;
|
13
13
|
export declare function narrowTypeForContainerElementType(evaluator: TypeEvaluator, referenceType: Type, elementType: Type): Type;
|
@@ -852,28 +852,29 @@ function getIsInstanceClassTypes(argType) {
|
|
852
852
|
});
|
853
853
|
return foundNonClassType ? undefined : classTypeList;
|
854
854
|
}
|
855
|
-
function isIsinstanceFilterSuperclass(evaluator, varType, filterType, concreteFilterType, isInstanceCheck) {
|
855
|
+
function isIsinstanceFilterSuperclass(evaluator, varType, concreteVarType, filterType, concreteFilterType, isInstanceCheck) {
|
856
|
+
if ((0, types_1.isTypeVar)(filterType)) {
|
857
|
+
return (0, types_1.isTypeSame)((0, typeUtils_1.convertToInstance)(filterType), varType);
|
858
|
+
}
|
856
859
|
// If the filter type represents all possible subclasses
|
857
860
|
// of a type, we can't make any statements about its superclass
|
858
|
-
// relationship with
|
861
|
+
// relationship with concreteVarType.
|
859
862
|
if (concreteFilterType.includeSubclasses) {
|
860
863
|
return false;
|
861
864
|
}
|
862
|
-
if ((
|
863
|
-
return false;
|
864
|
-
}
|
865
|
-
if (types_1.ClassType.isDerivedFrom(varType, concreteFilterType)) {
|
865
|
+
if (types_1.ClassType.isDerivedFrom(concreteVarType, concreteFilterType)) {
|
866
866
|
return true;
|
867
867
|
}
|
868
868
|
if (isInstanceCheck) {
|
869
|
-
if (types_1.ClassType.isProtocolClass(concreteFilterType) &&
|
869
|
+
if (types_1.ClassType.isProtocolClass(concreteFilterType) &&
|
870
|
+
evaluator.assignType(concreteFilterType, concreteVarType)) {
|
870
871
|
return true;
|
871
872
|
}
|
872
873
|
}
|
873
874
|
// Handle the special case where the variable type is a TypedDict and
|
874
875
|
// we're filtering against 'dict'. TypedDict isn't derived from dict,
|
875
876
|
// but at runtime, isinstance returns True.
|
876
|
-
if (types_1.ClassType.isBuiltIn(concreteFilterType, 'dict') && types_1.ClassType.isTypedDictClass(
|
877
|
+
if (types_1.ClassType.isBuiltIn(concreteFilterType, 'dict') && types_1.ClassType.isTypedDictClass(concreteVarType)) {
|
877
878
|
return true;
|
878
879
|
}
|
879
880
|
return false;
|
@@ -904,15 +905,15 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
904
905
|
// Filters the varType by the parameters of the isinstance
|
905
906
|
// and returns the list of types the varType could be after
|
906
907
|
// applying the filter.
|
907
|
-
const filterClassType = (varType,
|
908
|
+
const filterClassType = (varType, concreteVarType, conditions, negativeFallbackType) => {
|
908
909
|
const filteredTypes = [];
|
909
910
|
let foundSuperclass = false;
|
910
911
|
let isClassRelationshipIndeterminate = false;
|
911
912
|
for (const filterType of classTypeList) {
|
912
913
|
const concreteFilterType = evaluator.makeTopLevelTypeVarsConcrete(filterType);
|
913
914
|
if ((0, types_1.isInstantiableClass)(concreteFilterType)) {
|
914
|
-
const filterIsSuperclass = isIsinstanceFilterSuperclass(evaluator, varType, filterType, concreteFilterType, isInstanceCheck);
|
915
|
-
const filterIsSubclass = isIsinstanceFilterSubclass(evaluator,
|
915
|
+
const filterIsSuperclass = isIsinstanceFilterSuperclass(evaluator, varType, concreteVarType, filterType, concreteFilterType, isInstanceCheck);
|
916
|
+
const filterIsSubclass = isIsinstanceFilterSubclass(evaluator, concreteVarType, concreteFilterType, isInstanceCheck);
|
916
917
|
if (filterIsSuperclass) {
|
917
918
|
foundSuperclass = true;
|
918
919
|
}
|
@@ -923,17 +924,17 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
923
924
|
// will generate false positives.
|
924
925
|
if (filterIsSubclass &&
|
925
926
|
filterIsSuperclass &&
|
926
|
-
!types_1.ClassType.isSameGenericClass(
|
927
|
+
!types_1.ClassType.isSameGenericClass(concreteVarType, concreteFilterType)) {
|
927
928
|
isClassRelationshipIndeterminate = true;
|
928
929
|
}
|
929
930
|
if (isPositiveTest) {
|
930
931
|
if (filterIsSuperclass) {
|
931
932
|
// If the variable type is a subclass of the isinstance filter,
|
932
933
|
// we haven't learned anything new about the variable type.
|
933
|
-
filteredTypes.push((0, typeUtils_1.addConditionToType)(
|
934
|
+
filteredTypes.push((0, typeUtils_1.addConditionToType)(concreteVarType, conditions));
|
934
935
|
}
|
935
936
|
else if (filterIsSubclass) {
|
936
|
-
if (evaluator.assignType(
|
937
|
+
if (evaluator.assignType(concreteVarType, filterType,
|
937
938
|
/* diag */ undefined,
|
938
939
|
/* destTypeVarContext */ undefined,
|
939
940
|
/* srcTypeVarContext */ undefined, 512 /* IgnoreTypeVarScope */ | 4096 /* IgnoreProtocolAssignmentCheck */)) {
|
@@ -950,27 +951,27 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
950
951
|
const unspecializedFilterType = types_1.ClassType.cloneForSpecialization(filterType,
|
951
952
|
/* typeArguments */ undefined,
|
952
953
|
/* isTypeArgumentExplicit */ false);
|
953
|
-
if ((0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluator, unspecializedFilterType,
|
954
|
+
if ((0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluator, unspecializedFilterType, concreteVarType, typeVarContext,
|
954
955
|
/* liveTypeVarScopes */ undefined, errorNode.start)) {
|
955
956
|
specializedFilterType = (0, typeUtils_1.applySolvedTypeVars)(unspecializedFilterType, typeVarContext, { unknownIfNotFound: true });
|
956
957
|
}
|
957
958
|
}
|
958
959
|
}
|
959
|
-
filteredTypes.push((0, typeUtils_1.addConditionToType)(specializedFilterType,
|
960
|
+
filteredTypes.push((0, typeUtils_1.addConditionToType)(specializedFilterType, conditions));
|
960
961
|
}
|
961
962
|
}
|
962
963
|
else if (allowIntersections &&
|
963
|
-
!types_1.ClassType.isFinal(
|
964
|
+
!types_1.ClassType.isFinal(concreteVarType) &&
|
964
965
|
!types_1.ClassType.isFinal(concreteFilterType)) {
|
965
966
|
// The two types appear to have no relation. It's possible that the
|
966
967
|
// two types are protocols or the program is expecting one type to
|
967
968
|
// be a mix-in class used with the other. In this case, we'll
|
968
969
|
// synthesize a new class type that represents an intersection of
|
969
970
|
// the two types.
|
970
|
-
const className = `<subclass of ${
|
971
|
+
const className = `<subclass of ${concreteVarType.details.name} and ${concreteFilterType.details.name}>`;
|
971
972
|
const fileInfo = (0, analyzerNodeInfo_1.getFileInfo)(errorNode);
|
972
973
|
// The effective metaclass of the intersection is the narrower of the two metaclasses.
|
973
|
-
let effectiveMetaclass =
|
974
|
+
let effectiveMetaclass = concreteVarType.details.effectiveMetaclass;
|
974
975
|
if (concreteFilterType.details.effectiveMetaclass) {
|
975
976
|
if (!effectiveMetaclass ||
|
976
977
|
evaluator.assignType(effectiveMetaclass, concreteFilterType.details.effectiveMetaclass)) {
|
@@ -978,24 +979,27 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
978
979
|
}
|
979
980
|
}
|
980
981
|
let newClassType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.filePath, 0 /* None */, ParseTreeUtils.getTypeSourceId(errorNode),
|
981
|
-
/* declaredMetaclass */ undefined, effectiveMetaclass,
|
982
|
-
newClassType.details.baseClasses = [
|
982
|
+
/* declaredMetaclass */ undefined, effectiveMetaclass, concreteVarType.details.docString);
|
983
|
+
newClassType.details.baseClasses = [
|
984
|
+
types_1.ClassType.cloneAsInstantiable(concreteVarType),
|
985
|
+
concreteFilterType,
|
986
|
+
];
|
983
987
|
(0, typeUtils_1.computeMroLinearization)(newClassType);
|
984
988
|
newClassType = (0, typeUtils_1.addConditionToType)(newClassType, concreteFilterType.condition);
|
985
|
-
if ((0, types_1.isTypeVar)(
|
986
|
-
!
|
987
|
-
|
989
|
+
if ((0, types_1.isTypeVar)(varType) &&
|
990
|
+
!varType.details.isParamSpec &&
|
991
|
+
varType.details.constraints.length === 0) {
|
988
992
|
newClassType = (0, typeUtils_1.addConditionToType)(newClassType, [
|
989
993
|
{
|
990
|
-
typeVarName: types_1.TypeVarType.getNameWithScope(
|
994
|
+
typeVarName: types_1.TypeVarType.getNameWithScope(varType),
|
991
995
|
constraintIndex: 0,
|
992
996
|
isConstrainedTypeVar: false,
|
993
997
|
},
|
994
998
|
]);
|
995
999
|
}
|
996
1000
|
let newClassInstanceType = types_1.ClassType.cloneAsInstance(newClassType);
|
997
|
-
if (
|
998
|
-
newClassInstanceType = (0, typeUtils_1.addConditionToType)(newClassInstanceType,
|
1001
|
+
if (concreteVarType.condition) {
|
1002
|
+
newClassInstanceType = (0, typeUtils_1.addConditionToType)(newClassInstanceType, concreteVarType.condition);
|
999
1003
|
}
|
1000
1004
|
// If this is a issubclass check, we do a double conversion from instantiable
|
1001
1005
|
// to instance back to instantiable to make sure that the includeSubclasses flag
|
@@ -1007,12 +1011,15 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
1007
1011
|
else if ((0, types_1.isTypeVar)(filterType) && types_1.TypeBase.isInstantiable(filterType)) {
|
1008
1012
|
// Handle the case where the filter type is Type[T] and the unexpanded
|
1009
1013
|
// subtype is some instance type, possibly T.
|
1010
|
-
if (isInstanceCheck && types_1.TypeBase.isInstance(
|
1011
|
-
if ((0, types_1.isTypeVar)(
|
1014
|
+
if (isInstanceCheck && types_1.TypeBase.isInstance(varType)) {
|
1015
|
+
if ((0, types_1.isTypeVar)(varType) && (0, types_1.isTypeSame)((0, typeUtils_1.convertToInstance)(filterType), varType)) {
|
1012
1016
|
// If the unexpanded subtype is T, we can definitively filter
|
1013
1017
|
// in both the positive and negative cases.
|
1014
1018
|
if (isPositiveTest) {
|
1015
|
-
filteredTypes.push(
|
1019
|
+
filteredTypes.push(varType);
|
1020
|
+
}
|
1021
|
+
else {
|
1022
|
+
foundSuperclass = true;
|
1016
1023
|
}
|
1017
1024
|
}
|
1018
1025
|
else {
|
@@ -1022,15 +1029,15 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
1022
1029
|
else {
|
1023
1030
|
// If the unexpanded subtype is some other instance, we can't
|
1024
1031
|
// filter anything because it might be an instance.
|
1025
|
-
filteredTypes.push(
|
1032
|
+
filteredTypes.push(varType);
|
1026
1033
|
isClassRelationshipIndeterminate = true;
|
1027
1034
|
}
|
1028
1035
|
}
|
1029
1036
|
}
|
1030
|
-
else if (!isInstanceCheck && types_1.TypeBase.isInstantiable(
|
1031
|
-
if ((0, types_1.isTypeVar)(
|
1037
|
+
else if (!isInstanceCheck && types_1.TypeBase.isInstantiable(varType)) {
|
1038
|
+
if ((0, types_1.isTypeVar)(varType) && (0, types_1.isTypeSame)(filterType, varType)) {
|
1032
1039
|
if (isPositiveTest) {
|
1033
|
-
filteredTypes.push(
|
1040
|
+
filteredTypes.push(varType);
|
1034
1041
|
}
|
1035
1042
|
}
|
1036
1043
|
else {
|
@@ -1038,7 +1045,7 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
1038
1045
|
filteredTypes.push(filterType);
|
1039
1046
|
}
|
1040
1047
|
else {
|
1041
|
-
filteredTypes.push(
|
1048
|
+
filteredTypes.push(varType);
|
1042
1049
|
isClassRelationshipIndeterminate = true;
|
1043
1050
|
}
|
1044
1051
|
}
|
@@ -1048,22 +1055,27 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
1048
1055
|
// Handle an isinstance check against Callable.
|
1049
1056
|
if (isInstanceCheck) {
|
1050
1057
|
let isCallable = false;
|
1051
|
-
if ((0, types_1.isClass)(
|
1052
|
-
if (types_1.TypeBase.isInstantiable(
|
1058
|
+
if ((0, types_1.isClass)(concreteVarType)) {
|
1059
|
+
if (types_1.TypeBase.isInstantiable(varType)) {
|
1053
1060
|
isCallable = true;
|
1054
1061
|
}
|
1055
1062
|
else {
|
1056
|
-
isCallable = !!(0, typeUtils_1.lookUpClassMember)(
|
1063
|
+
isCallable = !!(0, typeUtils_1.lookUpClassMember)(concreteVarType, '__call__', 8 /* SkipInstanceVariables */);
|
1057
1064
|
}
|
1058
1065
|
}
|
1059
1066
|
if (isCallable) {
|
1060
1067
|
if (isPositiveTest) {
|
1061
|
-
filteredTypes.push(
|
1068
|
+
filteredTypes.push(varType);
|
1062
1069
|
}
|
1063
1070
|
else {
|
1064
1071
|
foundSuperclass = true;
|
1065
1072
|
}
|
1066
1073
|
}
|
1074
|
+
else if (evaluator.assignType(concreteVarType, filterType)) {
|
1075
|
+
if (isPositiveTest) {
|
1076
|
+
filteredTypes.push(filterType);
|
1077
|
+
}
|
1078
|
+
}
|
1067
1079
|
}
|
1068
1080
|
}
|
1069
1081
|
}
|
@@ -1085,6 +1097,53 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
1085
1097
|
}
|
1086
1098
|
return filteredTypes.map((t) => (0, typeUtils_1.convertToInstance)(t));
|
1087
1099
|
};
|
1100
|
+
// Filters the metaclassType (which is assumed to be a metaclass instance)
|
1101
|
+
// by the classTypeList and returns the list of types the varType could be
|
1102
|
+
// after applying the filter.
|
1103
|
+
const filterMetaclassType = (metaclassType, negativeFallbackType) => {
|
1104
|
+
const filteredTypes = [];
|
1105
|
+
let foundPositiveMatch = false;
|
1106
|
+
let isMatchIndeterminate = false;
|
1107
|
+
for (const filterType of classTypeList) {
|
1108
|
+
const concreteFilterType = evaluator.makeTopLevelTypeVarsConcrete(filterType);
|
1109
|
+
if ((0, types_1.isInstantiableClass)(concreteFilterType)) {
|
1110
|
+
const filterMetaclass = concreteFilterType.details.effectiveMetaclass;
|
1111
|
+
if (filterMetaclass && (0, types_1.isInstantiableClass)(filterMetaclass)) {
|
1112
|
+
const isMetaclassOverlap = evaluator.assignType(metaclassType, types_1.ClassType.cloneAsInstance(filterMetaclass));
|
1113
|
+
if (isMetaclassOverlap) {
|
1114
|
+
if (isPositiveTest) {
|
1115
|
+
filteredTypes.push(filterType);
|
1116
|
+
foundPositiveMatch = true;
|
1117
|
+
}
|
1118
|
+
else if (!(0, types_1.isTypeSame)(metaclassType, filterMetaclass) || filterMetaclass.includeSubclasses) {
|
1119
|
+
filteredTypes.push(metaclassType);
|
1120
|
+
isMatchIndeterminate = true;
|
1121
|
+
}
|
1122
|
+
}
|
1123
|
+
}
|
1124
|
+
else {
|
1125
|
+
filteredTypes.push(metaclassType);
|
1126
|
+
isMatchIndeterminate = true;
|
1127
|
+
}
|
1128
|
+
}
|
1129
|
+
else {
|
1130
|
+
filteredTypes.push(metaclassType);
|
1131
|
+
isMatchIndeterminate = true;
|
1132
|
+
}
|
1133
|
+
}
|
1134
|
+
// In the negative case, if one or more of the filters
|
1135
|
+
// always match the type in the positive case, then there's nothing
|
1136
|
+
// left after the filter is applied.
|
1137
|
+
if (!isPositiveTest) {
|
1138
|
+
if (!foundPositiveMatch || isMatchIndeterminate) {
|
1139
|
+
filteredTypes.push(negativeFallbackType);
|
1140
|
+
}
|
1141
|
+
}
|
1142
|
+
// We perform a double conversion from instance to instantiable
|
1143
|
+
// here to make sure that the includeSubclasses flag is cleared
|
1144
|
+
// if it's a class.
|
1145
|
+
return filteredTypes.map((t) => ((0, types_1.isInstantiableClass)(t) ? (0, typeUtils_1.convertToInstantiable)((0, typeUtils_1.convertToInstance)(t)) : t));
|
1146
|
+
};
|
1088
1147
|
const filterFunctionType = (varType, unexpandedType) => {
|
1089
1148
|
const filteredTypes = [];
|
1090
1149
|
if (isPositiveTest) {
|
@@ -1128,7 +1187,7 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
1128
1187
|
// on a constrained TypeVar that they want to filter based on its constrained
|
1129
1188
|
// parts.
|
1130
1189
|
const negativeFallback = (0, typeUtils_1.getTypeCondition)(subtype) ? subtype : unexpandedSubtype;
|
1131
|
-
const
|
1190
|
+
const isSubtypeMetaclass = (0, typeUtils_1.isMetaclassInstance)(subtype);
|
1132
1191
|
if (isPositiveTest && (0, types_1.isAnyOrUnknown)(subtype)) {
|
1133
1192
|
// If this is a positive test and the effective type is Any or
|
1134
1193
|
// Unknown, we can assume that the type matches one of the
|
@@ -1173,31 +1232,36 @@ function narrowTypeForIsInstance(evaluator, type, classTypeList, isInstanceCheck
|
|
1173
1232
|
}
|
1174
1233
|
}
|
1175
1234
|
}
|
1176
|
-
if ((0, types_1.isClassInstance)(subtype) && !
|
1177
|
-
return (0, types_1.combineTypes)(filterClassType(
|
1235
|
+
if ((0, types_1.isClassInstance)(subtype) && !isSubtypeMetaclass) {
|
1236
|
+
return (0, types_1.combineTypes)(filterClassType((0, typeUtils_1.convertToInstance)(unexpandedSubtype), types_1.ClassType.cloneAsInstantiable(subtype), (0, typeUtils_1.getTypeCondition)(subtype), negativeFallback));
|
1178
1237
|
}
|
1179
1238
|
if (((0, types_1.isFunction)(subtype) || (0, types_1.isOverloadedFunction)(subtype)) && isInstanceCheck) {
|
1180
1239
|
return (0, types_1.combineTypes)(filterFunctionType(subtype, (0, typeUtils_1.convertToInstance)(unexpandedSubtype)));
|
1181
1240
|
}
|
1182
|
-
if ((0, types_1.isInstantiableClass)(subtype) ||
|
1183
|
-
// Handle the special case of isinstance(x,
|
1184
|
-
const
|
1241
|
+
if ((0, types_1.isInstantiableClass)(subtype) || isSubtypeMetaclass) {
|
1242
|
+
// Handle the special case of isinstance(x, metaclass).
|
1243
|
+
const includesMetaclassType = classTypeList.some((classType) => (0, typeUtils_1.isInstantiableMetaclass)(classType));
|
1185
1244
|
if (isPositiveTest) {
|
1186
|
-
return
|
1245
|
+
return includesMetaclassType ? negativeFallback : undefined;
|
1187
1246
|
}
|
1188
1247
|
else {
|
1189
|
-
return
|
1248
|
+
return includesMetaclassType ? undefined : negativeFallback;
|
1190
1249
|
}
|
1191
1250
|
}
|
1192
1251
|
}
|
1193
1252
|
else {
|
1194
|
-
if ((0, types_1.
|
1195
|
-
|
1253
|
+
if ((0, types_1.isClass)(subtype)) {
|
1254
|
+
if ((0, types_1.isInstantiableClass)(subtype)) {
|
1255
|
+
return (0, types_1.combineTypes)(filterClassType(unexpandedSubtype, subtype, (0, typeUtils_1.getTypeCondition)(subtype), negativeFallback));
|
1256
|
+
}
|
1257
|
+
else if ((0, typeUtils_1.isMetaclassInstance)(subtype)) {
|
1258
|
+
return (0, types_1.combineTypes)(filterMetaclassType(subtype, negativeFallback));
|
1259
|
+
}
|
1196
1260
|
}
|
1197
|
-
if (
|
1261
|
+
if (isSubtypeMetaclass) {
|
1198
1262
|
const objectType = evaluator.getBuiltInObject(errorNode, 'object');
|
1199
1263
|
if (objectType && (0, types_1.isClassInstance)(objectType)) {
|
1200
|
-
return (0, types_1.combineTypes)(filterClassType(
|
1264
|
+
return (0, types_1.combineTypes)(filterClassType((0, typeUtils_1.convertToInstantiable)(unexpandedSubtype), types_1.ClassType.cloneAsInstantiable(objectType), (0, typeUtils_1.getTypeCondition)(subtype), negativeFallback));
|
1201
1265
|
}
|
1202
1266
|
}
|
1203
1267
|
}
|
@@ -1566,9 +1630,11 @@ function narrowTypeForTypeIs(evaluator, type, classType, isPositiveTest) {
|
|
1566
1630
|
}
|
1567
1631
|
return (0, typeUtils_1.addConditionToType)(types_1.ClassType.cloneAsInstance(classType), subtype.condition);
|
1568
1632
|
}
|
1569
|
-
|
1633
|
+
if (!classType.includeSubclasses) {
|
1634
|
+
return undefined;
|
1635
|
+
}
|
1570
1636
|
}
|
1571
|
-
else {
|
1637
|
+
else if (!classType.includeSubclasses) {
|
1572
1638
|
// If the class if marked final and it matches, then
|
1573
1639
|
// we can eliminate it in the negative case.
|
1574
1640
|
if (matches && types_1.ClassType.isFinal(subtype)) {
|
@@ -1606,7 +1672,7 @@ function narrowTypeForClassComparison(evaluator, referenceType, classType, isPos
|
|
1606
1672
|
}
|
1607
1673
|
if ((0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isFinal(concreteSubtype)) {
|
1608
1674
|
if (!types_1.ClassType.isSameGenericClass(concreteSubtype, classType) &&
|
1609
|
-
!isIsinstanceFilterSuperclass(evaluator, concreteSubtype, classType, classType,
|
1675
|
+
!isIsinstanceFilterSuperclass(evaluator, subtype, concreteSubtype, classType, classType,
|
1610
1676
|
/* isInstanceCheck */ false)) {
|
1611
1677
|
return undefined;
|
1612
1678
|
}
|
@@ -1628,7 +1694,13 @@ function narrowTypeForClassComparison(evaluator, referenceType, classType, isPos
|
|
1628
1694
|
function narrowTypeForLiteralComparison(evaluator, referenceType, literalType, isPositiveTest, isIsOperator) {
|
1629
1695
|
return (0, typeUtils_1.mapSubtypes)(referenceType, (subtype) => {
|
1630
1696
|
subtype = evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
1631
|
-
if ((0, types_1.
|
1697
|
+
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
1698
|
+
if (isPositiveTest) {
|
1699
|
+
return literalType;
|
1700
|
+
}
|
1701
|
+
return subtype;
|
1702
|
+
}
|
1703
|
+
else if ((0, types_1.isClassInstance)(subtype) && types_1.ClassType.isSameGenericClass(literalType, subtype)) {
|
1632
1704
|
if (subtype.literalValue !== undefined) {
|
1633
1705
|
const literalValueMatches = types_1.ClassType.isLiteralValueSame(subtype, literalType);
|
1634
1706
|
if ((literalValueMatches && !isPositiveTest) || (!literalValueMatches && isPositiveTest)) {
|