@zzzen/pyright-internal 1.2.0-dev.20260927 → 1.2.0-dev.20261011
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/analyzerNodeInfo.js +7 -2
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +17 -6
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +0 -2
- package/dist/analyzer/checker.js +23 -47
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -0
- package/dist/analyzer/codeFlowEngine.js +155 -18
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.d.ts +2 -1
- package/dist/analyzer/codeFlowTypes.js +1 -0
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/codeFlowUtils.js +4 -1
- package/dist/analyzer/codeFlowUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +3 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/operations.d.ts +2 -0
- package/dist/analyzer/operations.js +2 -1
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +2 -1
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +80 -11
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +4 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.d.ts +2 -2
- package/dist/analyzer/properties.js +2 -2
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +3 -1
- package/dist/analyzer/protocols.js +35 -5
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/symbolNameUtils.d.ts +1 -0
- package/dist/analyzer/symbolNameUtils.js +5 -0
- package/dist/analyzer/symbolNameUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +269 -32
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +4 -2
- package/dist/analyzer/typeEvaluatorTypes.js +4 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +208 -68
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +32 -6
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +24 -2
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +8 -4
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -1
- package/dist/analyzer/types.js +9 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/extensibility.d.ts +1 -0
- package/dist/common/processUtils.d.ts +9 -1
- package/dist/common/processUtils.js +52 -10
- package/dist/common/processUtils.js.map +1 -1
- package/dist/common/windowsProcessTree.d.ts +4 -0
- package/dist/common/windowsProcessTree.js +47 -0
- package/dist/common/windowsProcessTree.js.map +1 -0
- package/dist/common/windowsProcessTree.json +310 -0
- package/dist/languageService/callHierarchyProvider.js +12 -4
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/localization/package.nls.pl.json +2 -2
- package/dist/localization/package.nls.pt-br.json +1 -1
- package/dist/localization/package.nls.zh-cn.json +2 -2
- package/dist/localization/package.nls.zh-tw.json +1 -1
- package/dist/tests/cacheManager.test.js +19 -15
- package/dist/tests/cacheManager.test.js.map +1 -1
- package/dist/tests/constraintSolver.test.d.ts +1 -0
- package/dist/tests/constraintSolver.test.js +39 -0
- package/dist/tests/constraintSolver.test.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.metaclass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.metaclass.fourslash.js +44 -0
- package/dist/tests/fourslash/findDefinitions.metaclass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.metaclassDict.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.metaclassDict.fourslash.js +42 -0
- package/dist/tests/fourslash/findDefinitions.metaclassDict.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.typedDictUnpacking.dictDisplay.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.typedDictUnpacking.dictDisplay.fourslash.js +16 -0
- package/dist/tests/fourslash/hover.typedDictUnpacking.dictDisplay.fourslash.js.map +1 -0
- package/dist/tests/mypyPrimerAnalysis.test.js +67 -11
- package/dist/tests/mypyPrimerAnalysis.test.js.map +1 -1
- package/dist/tests/mypyPrimerMcp.test.js +2 -1
- package/dist/tests/mypyPrimerMcp.test.js.map +1 -1
- package/dist/tests/service.test.js +36 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/typeEquality.test.js +85 -2
- package/dist/tests/typeEquality.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +55 -2
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +23 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +75 -1
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +22 -0
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +41 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/tests/typeServer/inProcTypeServerTestUtils.d.ts +7 -2
- package/dist/tests/typeServer/inProcTypeServerTestUtils.js +14 -7
- package/dist/tests/typeServer/inProcTypeServerTestUtils.js.map +1 -1
- package/dist/tests/typeServer/stubGenerator.test.js +29 -0
- package/dist/tests/typeServer/stubGenerator.test.js.map +1 -1
- package/dist/tests/typeServer/typeServer.inProc.test.js +87 -1
- package/dist/tests/typeServer/typeServer.inProc.test.js.map +1 -1
- package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js +15 -0
- package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js.map +1 -1
- package/dist/typeServer/stubGenerator.js +5 -6
- package/dist/typeServer/stubGenerator.js.map +1 -1
- package/dist/workspaceFactory.js +5 -0
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +3 -3
|
@@ -95,6 +95,7 @@ const typedDicts_1 = require("./typedDicts");
|
|
|
95
95
|
const typeEvaluatorTypes_1 = require("./typeEvaluatorTypes");
|
|
96
96
|
const typeGuards_1 = require("./typeGuards");
|
|
97
97
|
const TypePrinter = __importStar(require("./typePrinter"));
|
|
98
|
+
const typeWalker_1 = require("./typeWalker");
|
|
98
99
|
const types_1 = require("./types");
|
|
99
100
|
const typeUtils_1 = require("./typeUtils");
|
|
100
101
|
const overloadResultSelector_1 = require("./overloadResultSelector");
|
|
@@ -204,6 +205,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
204
205
|
let typeCache = new Map();
|
|
205
206
|
let typeFormTypeCache = new Map();
|
|
206
207
|
let effectiveTypeCache = new Map();
|
|
208
|
+
let exceptionTargetSymbolCache = new Map();
|
|
207
209
|
let expectedTypeCache = new Map();
|
|
208
210
|
let asymmetricAccessorAssignmentCache = new Set();
|
|
209
211
|
let deferredClassCompletions = [];
|
|
@@ -271,6 +273,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
271
273
|
typeCache = new Map();
|
|
272
274
|
typeFormTypeCache = new Map();
|
|
273
275
|
effectiveTypeCache = new Map();
|
|
276
|
+
exceptionTargetSymbolCache = new Map();
|
|
274
277
|
expectedTypeCache = new Map();
|
|
275
278
|
asymmetricAccessorAssignmentCache = new Set();
|
|
276
279
|
}
|
|
@@ -1835,11 +1838,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1835
1838
|
}
|
|
1836
1839
|
const argList = [];
|
|
1837
1840
|
let previousCategory = 0 /* ArgCategory.Simple */;
|
|
1841
|
+
let hasFakeArg = false;
|
|
1838
1842
|
// Empty arguments do not enter the AST as nodes, but instead are left blank.
|
|
1839
1843
|
// Instead, we detect when we appear to be between two known arguments or at the
|
|
1840
1844
|
// end of the argument list and insert a fake argument of an unknown type to have
|
|
1841
1845
|
// something to match later.
|
|
1842
1846
|
function addFakeArg() {
|
|
1847
|
+
hasFakeArg = true;
|
|
1843
1848
|
argList.push({
|
|
1844
1849
|
argCategory: previousCategory,
|
|
1845
1850
|
typeResult: { type: types_1.UnknownType.create() },
|
|
@@ -1876,7 +1881,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1876
1881
|
/* skipUnknownArgCheck */ true,
|
|
1877
1882
|
/* inferenceContext */ undefined);
|
|
1878
1883
|
});
|
|
1879
|
-
|
|
1884
|
+
let specializedType = type;
|
|
1885
|
+
if (types_1.FunctionType.getParamSpecFromArgsKwargs(type)) {
|
|
1886
|
+
const solution = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints);
|
|
1887
|
+
// The fake argument is used only to identify the active parameter. Preserve
|
|
1888
|
+
// type variables in that parameter while specializing the forwarded ParamSpec.
|
|
1889
|
+
if (hasFakeArg && callResult?.activeParam) {
|
|
1890
|
+
const activeParamIndex = type.shared.parameters.indexOf(callResult.activeParam);
|
|
1891
|
+
if (activeParamIndex >= 0) {
|
|
1892
|
+
(0, typeUtils_1.getTypeVarArgsRecursive)(types_1.FunctionType.getParamType(type, activeParamIndex)).forEach((typeVar) => {
|
|
1893
|
+
if (!(0, types_1.isParamSpec)(typeVar)) {
|
|
1894
|
+
solution.doForEachSolutionSet((solutionSet) => {
|
|
1895
|
+
const solvedType = solutionSet.getType(typeVar);
|
|
1896
|
+
if (!solvedType || (0, types_1.isUnknown)(solvedType)) {
|
|
1897
|
+
solutionSet.setType(typeVar, typeVar);
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
specializedType = (0, typeUtils_1.applySolvedTypeVars)(type, solution);
|
|
1905
|
+
}
|
|
1880
1906
|
const finalType = (0, types_1.isFunction)(specializedType) ? specializedType : type;
|
|
1881
1907
|
const hasActiveArg = argList.some((arg) => arg.active);
|
|
1882
1908
|
// If the type was specialized (e.g. ParamSpec expansion), the activeParam
|
|
@@ -2725,6 +2751,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2725
2751
|
const memberInfo = (0, typeUtils_1.lookUpClassMember)(classType.classType, nameNode.d.value, 1 /* MemberAccessFlags.SkipOriginalClass */);
|
|
2726
2752
|
if (memberInfo?.isTypeDeclared) {
|
|
2727
2753
|
declaredType = getTypeOfMember(memberInfo);
|
|
2754
|
+
if ((0, symbolNameUtils_1.isMethodExemptFromLsp)(nameValue) &&
|
|
2755
|
+
memberInfo.symbol
|
|
2756
|
+
.getTypedDeclarations()
|
|
2757
|
+
.some((decl) => decl.type === 5 /* DeclarationType.Function */) &&
|
|
2758
|
+
(0, types_1.isFunctionOrOverloaded)(typeResult.type) &&
|
|
2759
|
+
(0, types_1.isFunctionOrOverloaded)(declaredType) &&
|
|
2760
|
+
!isFinalVariable(memberInfo.symbol)) {
|
|
2761
|
+
const baseMethods = (0, types_1.isFunction)(declaredType)
|
|
2762
|
+
? [declaredType]
|
|
2763
|
+
: [
|
|
2764
|
+
...types_1.OverloadedType.getOverloads(declaredType),
|
|
2765
|
+
types_1.OverloadedType.getImplementation(declaredType),
|
|
2766
|
+
];
|
|
2767
|
+
if (!baseMethods.some((method) => method && (0, types_1.isFunction)(method) && types_1.FunctionType.isFinal(method))) {
|
|
2768
|
+
// Apply the same override exemptions to aliases and method definitions.
|
|
2769
|
+
declaredType = undefined;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2728
2772
|
}
|
|
2729
2773
|
}
|
|
2730
2774
|
}
|
|
@@ -4570,6 +4614,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4570
4614
|
const isAccessedThroughObject = types_1.TypeBase.isInstance(classType);
|
|
4571
4615
|
// Always look for a member with a declared type first.
|
|
4572
4616
|
let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, flags | 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
|
4617
|
+
// A class-level method alias retains its inferred signature, unlike an annotated variable.
|
|
4618
|
+
if (usage.method === 'get' &&
|
|
4619
|
+
memberInfo?.skippedUndeclaredType &&
|
|
4620
|
+
memberInfo.symbol.getTypedDeclarations().some((decl) => decl.type === 5 /* DeclarationType.Function */)) {
|
|
4621
|
+
const inferredMember = (0, typeUtils_1.lookUpClassMember)(classType, memberName, flags);
|
|
4622
|
+
if (inferredMember?.isClassMember &&
|
|
4623
|
+
!inferredMember.isInstanceMember &&
|
|
4624
|
+
(0, types_1.isFunctionOrOverloaded)(getTypeOfMember(inferredMember))) {
|
|
4625
|
+
memberInfo = inferredMember;
|
|
4626
|
+
}
|
|
4627
|
+
}
|
|
4573
4628
|
// If we couldn't find a symbol with a declared type, use
|
|
4574
4629
|
// a symbol with an inferred type.
|
|
4575
4630
|
if (!memberInfo) {
|
|
@@ -4818,7 +4873,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4818
4873
|
const subDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
|
4819
4874
|
const methodTypeResult = getTypeOfBoundMember(errorNode, concreteMemberType, accessMethodName,
|
|
4820
4875
|
/* usage */ undefined, subDiag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */);
|
|
4821
|
-
|
|
4876
|
+
const deferredMethodType = usage.method === 'get'
|
|
4877
|
+
? getDescriptorGetMethodWithDeferredSelfSpecialization(concreteMemberType, subDiag)
|
|
4878
|
+
: undefined;
|
|
4879
|
+
if ((!methodTypeResult || methodTypeResult.typeErrors) && !deferredMethodType) {
|
|
4822
4880
|
// Provide special error messages for properties.
|
|
4823
4881
|
if (types_1.ClassType.isPropertyClass(concreteMemberType) && usage.method !== 'get') {
|
|
4824
4882
|
const message = usage.method === 'set' ? localize_1.LocAddendum.propertyMissingSetter() : localize_1.LocAddendum.propertyMissingDeleter();
|
|
@@ -4830,9 +4888,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4830
4888
|
}
|
|
4831
4889
|
return { type: memberType };
|
|
4832
4890
|
}
|
|
4833
|
-
const methodClassType = methodTypeResult
|
|
4834
|
-
let methodType = methodTypeResult.type;
|
|
4835
|
-
if (
|
|
4891
|
+
const methodClassType = methodTypeResult?.classType ?? concreteMemberType;
|
|
4892
|
+
let methodType = deferredMethodType ?? methodTypeResult.type;
|
|
4893
|
+
if (!methodClassType) {
|
|
4836
4894
|
if (diag && subDiag) {
|
|
4837
4895
|
diag.addAddendum(subDiag);
|
|
4838
4896
|
}
|
|
@@ -4889,8 +4947,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4889
4947
|
}
|
|
4890
4948
|
// Determine if we're calling __set__ on an asymmetric descriptor or property.
|
|
4891
4949
|
let isAsymmetricAccessor = false;
|
|
4892
|
-
if (usage.method === 'set'
|
|
4893
|
-
if (isAsymmetricDescriptorClass(
|
|
4950
|
+
if (usage.method === 'set') {
|
|
4951
|
+
if (isAsymmetricDescriptorClass(concreteMemberType)) {
|
|
4894
4952
|
isAsymmetricAccessor = true;
|
|
4895
4953
|
}
|
|
4896
4954
|
}
|
|
@@ -4993,6 +5051,65 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4993
5051
|
memberAccessDeprecationInfo: deprecationInfo,
|
|
4994
5052
|
};
|
|
4995
5053
|
}
|
|
5054
|
+
function getDescriptorGetMethodWithDeferredSelfSpecialization(concreteMemberType, diag) {
|
|
5055
|
+
const member = (0, typeUtils_1.lookUpClassMember)(concreteMemberType, '__get__');
|
|
5056
|
+
if (!member || !(0, types_1.isInstantiableClass)(member.unspecializedClassType)) {
|
|
5057
|
+
return undefined;
|
|
5058
|
+
}
|
|
5059
|
+
const unspecializedClassType = member.unspecializedClassType;
|
|
5060
|
+
const declaringClassType = member.classType;
|
|
5061
|
+
if (!(0, types_1.isInstantiableClass)(declaringClassType)) {
|
|
5062
|
+
return undefined;
|
|
5063
|
+
}
|
|
5064
|
+
const declaringObjectType = types_1.ClassType.cloneAsInstance(declaringClassType);
|
|
5065
|
+
const unspecializedMethodType = getEffectiveTypeOfSymbol(member.symbol);
|
|
5066
|
+
if (!(0, types_1.isFunctionOrOverloaded)(unspecializedMethodType)) {
|
|
5067
|
+
return undefined;
|
|
5068
|
+
}
|
|
5069
|
+
// A class ParamSpec used in Concatenate within the self annotation needs to be
|
|
5070
|
+
// solved from the concrete descriptor, rather than specialized before self is bound.
|
|
5071
|
+
const classParamSpecs = types_1.ClassType.getTypeParams(unspecializedClassType).filter(types_1.isParamSpec);
|
|
5072
|
+
if (classParamSpecs.length === 0) {
|
|
5073
|
+
return undefined;
|
|
5074
|
+
}
|
|
5075
|
+
const signatures = (0, types_1.isFunction)(unspecializedMethodType)
|
|
5076
|
+
? [unspecializedMethodType]
|
|
5077
|
+
: types_1.OverloadedType.getOverloads(unspecializedMethodType);
|
|
5078
|
+
const shouldDefer = signatures.some((signature) => {
|
|
5079
|
+
if (signature.shared.parameters.length === 0) {
|
|
5080
|
+
return false;
|
|
5081
|
+
}
|
|
5082
|
+
const selfParamType = types_1.FunctionType.getParamType(signature, 0);
|
|
5083
|
+
if (!(0, types_1.isClassInstance)(selfParamType) || !types_1.ClassType.isSameGenericClass(selfParamType, declaringObjectType)) {
|
|
5084
|
+
return false;
|
|
5085
|
+
}
|
|
5086
|
+
class ConcatenateParamSpecWalker extends typeWalker_1.TypeWalker {
|
|
5087
|
+
constructor() {
|
|
5088
|
+
super(...arguments);
|
|
5089
|
+
this.found = false;
|
|
5090
|
+
}
|
|
5091
|
+
visitFunction(type) {
|
|
5092
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
|
5093
|
+
if (paramSpec &&
|
|
5094
|
+
types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type).shared.parameters.length > 0 &&
|
|
5095
|
+
classParamSpecs.some((classParamSpec) => (0, types_1.isTypeSame)(paramSpec, classParamSpec))) {
|
|
5096
|
+
this.found = true;
|
|
5097
|
+
this.cancelWalk();
|
|
5098
|
+
return;
|
|
5099
|
+
}
|
|
5100
|
+
super.visitFunction(type);
|
|
5101
|
+
}
|
|
5102
|
+
}
|
|
5103
|
+
const walker = new ConcatenateParamSpecWalker();
|
|
5104
|
+
selfParamType.priv.typeArgs?.forEach((typeArg) => walker.walk(typeArg));
|
|
5105
|
+
return walker.found;
|
|
5106
|
+
});
|
|
5107
|
+
if (!shouldDefer) {
|
|
5108
|
+
return undefined;
|
|
5109
|
+
}
|
|
5110
|
+
return bindFunctionToClassOrObject(declaringObjectType, unspecializedMethodType, declaringClassType,
|
|
5111
|
+
/* treatConstructorAsClassMethod */ false, concreteMemberType, diag);
|
|
5112
|
+
}
|
|
4996
5113
|
function bindMethodForMemberAccess(type, concreteType, memberInfo, classType, selfType, flags, memberName, usage, diag, recursionCount = 0) {
|
|
4997
5114
|
// Check for an attempt to overwrite a final method.
|
|
4998
5115
|
if (usage.method === 'set') {
|
|
@@ -5021,14 +5138,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
5021
5138
|
return classType.priv.isAsymmetricDescriptor;
|
|
5022
5139
|
}
|
|
5023
5140
|
let isAsymmetric = false;
|
|
5024
|
-
|
|
5025
|
-
|
|
5141
|
+
// Accessors can be defined at different levels of the descriptor's MRO.
|
|
5142
|
+
// Ignore instance members so an instance attribute that happens to share
|
|
5143
|
+
// a dunder name doesn't shadow the descriptor protocol during this check.
|
|
5144
|
+
const accessorFlags = 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */;
|
|
5145
|
+
const getterSymbolResult = (0, typeUtils_1.lookUpClassMember)(classType, '__get__', accessorFlags);
|
|
5146
|
+
const setterSymbolResult = (0, typeUtils_1.lookUpClassMember)(classType, '__set__', accessorFlags);
|
|
5026
5147
|
if (!getterSymbolResult || !setterSymbolResult) {
|
|
5027
5148
|
isAsymmetric = false;
|
|
5028
5149
|
}
|
|
5029
5150
|
else {
|
|
5030
5151
|
let getterType = getTypeOfMember(getterSymbolResult);
|
|
5031
|
-
|
|
5152
|
+
let setterType = getTypeOfMember(setterSymbolResult);
|
|
5153
|
+
// The getter and setter can be declared on different classes. Specialize
|
|
5154
|
+
// both against the concrete descriptor class so Self and inherited type
|
|
5155
|
+
// variables are compared in the same context.
|
|
5156
|
+
if (getterSymbolResult.classType && (0, types_1.isInstantiableClass)(getterSymbolResult.classType)) {
|
|
5157
|
+
getterType = (0, typeUtils_1.partiallySpecializeType)(getterType, getterSymbolResult.classType, getTypeClassType(), classType);
|
|
5158
|
+
}
|
|
5159
|
+
if (setterSymbolResult.classType && (0, types_1.isInstantiableClass)(setterSymbolResult.classType)) {
|
|
5160
|
+
setterType = (0, typeUtils_1.partiallySpecializeType)(setterType, setterSymbolResult.classType, getTypeClassType(), classType);
|
|
5161
|
+
}
|
|
5032
5162
|
// If this is an overload, find the appropriate overload.
|
|
5033
5163
|
if ((0, types_1.isOverloaded)(getterType)) {
|
|
5034
5164
|
const getOverloads = types_1.OverloadedType.getOverloads(getterType).filter((overload) => {
|
|
@@ -10807,7 +10937,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10807
10937
|
const tdEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, unexpandedType,
|
|
10808
10938
|
/* allowNarrowed */ true);
|
|
10809
10939
|
tdEntries.knownItems.forEach((entry, name) => {
|
|
10810
|
-
if (entry.isRequired || entry.isProvided) {
|
|
10940
|
+
if (!expectedTypedDictEntries || entry.isRequired || entry.isProvided) {
|
|
10811
10941
|
keyTypes.push({
|
|
10812
10942
|
node: entryNode,
|
|
10813
10943
|
type: types_1.ClassType.cloneWithLiteral(strObject, name),
|
|
@@ -10816,6 +10946,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10816
10946
|
}
|
|
10817
10947
|
});
|
|
10818
10948
|
if (!expectedTypedDictEntries) {
|
|
10949
|
+
// Open TypedDicts can contain extra items with arbitrary value types.
|
|
10819
10950
|
keyTypes.push({ node: entryNode, type: types_1.ClassType.cloneAsInstance(strObject) });
|
|
10820
10951
|
valueTypes.push({
|
|
10821
10952
|
node: entryNode,
|
|
@@ -11215,27 +11346,62 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11215
11346
|
// Pre-cache the incomplete function type in case the evaluation of the
|
|
11216
11347
|
// lambda depends on itself.
|
|
11217
11348
|
writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* EvalFlags.None */);
|
|
11218
|
-
//
|
|
11219
|
-
//
|
|
11220
|
-
// object for any lambda parameters that don't match. We could make this
|
|
11221
|
-
// more sophisticated in the future, but it becomes very complex to handle
|
|
11222
|
-
// all of the permutations.
|
|
11349
|
+
// Match positional parameters in order, but allow keyword-only parameters
|
|
11350
|
+
// to be reordered. Unmatched parameters without defaults use Unknown.
|
|
11223
11351
|
let sawParamMismatch = false;
|
|
11352
|
+
let expectedParamIndex = 0;
|
|
11353
|
+
let expectedKeywordParams;
|
|
11354
|
+
const positionOnlySeparatorIndex = node.d.params.findIndex((param) => param.d.category === 0 /* ParamCategory.Simple */ && !param.d.name);
|
|
11224
11355
|
node.d.params.forEach((param, index) => {
|
|
11225
11356
|
let paramType;
|
|
11226
11357
|
if (expectedParamDetails && !sawParamMismatch) {
|
|
11227
|
-
|
|
11228
|
-
|
|
11358
|
+
const isKeywordOnlySeparator = param.d.category === 1 /* ParamCategory.ArgsList */ && !param.d.name;
|
|
11359
|
+
if (isKeywordOnlySeparator) {
|
|
11360
|
+
if (expectedParamIndex < expectedParamDetails.params.length &&
|
|
11361
|
+
expectedParamDetails.params[expectedParamIndex].kind !== parameterUtils_1.ParamKind.Keyword) {
|
|
11362
|
+
sawParamMismatch = true;
|
|
11363
|
+
}
|
|
11364
|
+
}
|
|
11365
|
+
else if (expectedParamIndex < expectedParamDetails.params.length) {
|
|
11366
|
+
let expectedParam = expectedParamDetails.params[expectedParamIndex];
|
|
11367
|
+
const isPositionOnlyParam = (positionOnlySeparatorIndex >= 0 && index < positionOnlySeparatorIndex) ||
|
|
11368
|
+
(positionOnlySeparatorIndex < 0 &&
|
|
11369
|
+
paramsArePositionOnly &&
|
|
11370
|
+
!!param.d.name &&
|
|
11371
|
+
(0, symbolNameUtils_1.isPrivateName)(param.d.name.d.value));
|
|
11372
|
+
if (expectedParam.kind === parameterUtils_1.ParamKind.Keyword &&
|
|
11373
|
+
expectedParam.param.category === 0 /* ParamCategory.Simple */ &&
|
|
11374
|
+
param.d.category === 0 /* ParamCategory.Simple */ &&
|
|
11375
|
+
param.d.name &&
|
|
11376
|
+
!isPositionOnlyParam &&
|
|
11377
|
+
param.d.name.d.value !== expectedParam.param.name) {
|
|
11378
|
+
if (!expectedKeywordParams) {
|
|
11379
|
+
expectedKeywordParams = new Map();
|
|
11380
|
+
for (const keywordParam of expectedParamDetails.params) {
|
|
11381
|
+
if (keywordParam.kind === parameterUtils_1.ParamKind.Keyword &&
|
|
11382
|
+
keywordParam.param.category === 0 /* ParamCategory.Simple */ &&
|
|
11383
|
+
keywordParam.param.name) {
|
|
11384
|
+
expectedKeywordParams.set(keywordParam.param.name, keywordParam);
|
|
11385
|
+
}
|
|
11386
|
+
}
|
|
11387
|
+
}
|
|
11388
|
+
expectedParam = expectedKeywordParams.get(param.d.name.d.value) ?? expectedParam;
|
|
11389
|
+
}
|
|
11390
|
+
const isCompatibleKeywordParam = expectedParam.kind !== parameterUtils_1.ParamKind.Keyword ||
|
|
11391
|
+
expectedParam.param.category === 2 /* ParamCategory.KwargsDict */ ||
|
|
11392
|
+
(!isPositionOnlyParam && param.d.name?.d.value === expectedParam.param.name);
|
|
11229
11393
|
// If the parameter category matches and both of the parameters are
|
|
11230
11394
|
// either separators (/ or *) or not separators, copy the type
|
|
11231
11395
|
// from the expected parameter.
|
|
11232
11396
|
if (expectedParam.param.category === param.d.category &&
|
|
11233
|
-
!param.d.name === !expectedParam.param.name
|
|
11397
|
+
!param.d.name === !expectedParam.param.name &&
|
|
11398
|
+
isCompatibleKeywordParam) {
|
|
11234
11399
|
paramType = expectedParam.type;
|
|
11235
11400
|
}
|
|
11236
11401
|
else {
|
|
11237
11402
|
sawParamMismatch = true;
|
|
11238
11403
|
}
|
|
11404
|
+
expectedParamIndex++;
|
|
11239
11405
|
}
|
|
11240
11406
|
else if (param.d.defaultValue) {
|
|
11241
11407
|
// If the lambda param has a default value but there is no associated
|
|
@@ -11250,15 +11416,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11250
11416
|
// use the default value to infer the parameter's type.
|
|
11251
11417
|
paramType = inferParamTypeFromDefaultValue(param.d.defaultValue);
|
|
11252
11418
|
}
|
|
11419
|
+
if (param.d.defaultValue) {
|
|
11420
|
+
const defaultValueResult = getTypeOfExpression(param.d.defaultValue, 1 /* EvalFlags.ConvertEllipsisToAny */, (0, typeUtils_1.makeInferenceContext)(paramType));
|
|
11421
|
+
if (defaultValueResult.isIncomplete) {
|
|
11422
|
+
isIncomplete = true;
|
|
11423
|
+
}
|
|
11424
|
+
// The lambda can also be called with its own default value.
|
|
11425
|
+
if (paramType && !assignType(paramType, defaultValueResult.type)) {
|
|
11426
|
+
paramType = (0, types_1.combineTypes)([paramType, stripLiteralValue(defaultValueResult.type)]);
|
|
11427
|
+
}
|
|
11428
|
+
}
|
|
11253
11429
|
if (param.d.name) {
|
|
11254
11430
|
writeTypeCache(param.d.name, {
|
|
11255
11431
|
type: transformVariadicParamType(node, param.d.category, paramType ?? types_1.UnknownType.create()),
|
|
11256
11432
|
}, 0 /* EvalFlags.None */);
|
|
11257
11433
|
}
|
|
11258
|
-
if (param.d.defaultValue) {
|
|
11259
|
-
// Evaluate the default value if it's present.
|
|
11260
|
-
getTypeOfExpression(param.d.defaultValue, 1 /* EvalFlags.ConvertEllipsisToAny */);
|
|
11261
|
-
}
|
|
11262
11434
|
// Determine whether we need to insert an implied position-only parameter.
|
|
11263
11435
|
// This is needed when a function's parameters are named using the old-style
|
|
11264
11436
|
// way of specifying position-only parameters.
|
|
@@ -13442,6 +13614,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13442
13614
|
// Determine the effective metaclass.
|
|
13443
13615
|
if (metaclassNode) {
|
|
13444
13616
|
let metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
|
|
13617
|
+
if ((0, types_1.isAny)(metaclassType)) {
|
|
13618
|
+
metaclassType = types_1.UnknownType.create();
|
|
13619
|
+
}
|
|
13445
13620
|
if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
|
|
13446
13621
|
if ((0, typeUtils_1.requiresSpecialization)(metaclassType, { ignorePseudoGeneric: true })) {
|
|
13447
13622
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.metaclassIsGeneric(), metaclassNode);
|
|
@@ -13464,6 +13639,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13464
13639
|
}
|
|
13465
13640
|
}
|
|
13466
13641
|
}
|
|
13642
|
+
else {
|
|
13643
|
+
// Callable metaclasses can return classes with different equality semantics.
|
|
13644
|
+
classType.shared.flags |= 134217728 /* ClassTypeFlags.HasUnresolvedMetaclass */;
|
|
13645
|
+
}
|
|
13467
13646
|
}
|
|
13468
13647
|
const effectiveMetaclass = computeEffectiveMetaclass(classType, node.d.name);
|
|
13469
13648
|
const enumMemberSetMayBeDynamicallyModified = types_1.ClassType.isEnumClass(classType) &&
|
|
@@ -14876,9 +15055,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14876
15055
|
}
|
|
14877
15056
|
return getExceptionType(subType, node.d.typeExpr);
|
|
14878
15057
|
});
|
|
14879
|
-
// If this is an except group,
|
|
14880
|
-
//
|
|
14881
|
-
// a BaseException.
|
|
15058
|
+
// If this is an except group, use a BaseExceptionGroup when it can contain
|
|
15059
|
+
// an exception outside the Exception hierarchy.
|
|
14882
15060
|
if (node.d.isExceptGroup) {
|
|
14883
15061
|
targetType = getBuiltInObject(node, includesBaseException ? 'BaseExceptionGroup' : 'ExceptionGroup', [
|
|
14884
15062
|
targetType,
|
|
@@ -17681,8 +17859,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17681
17859
|
// This will avoid a pathological performance condition for unannotated
|
|
17682
17860
|
// code that reassigns the same variable hundreds of times. If the symbol
|
|
17683
17861
|
// effectively has an "Any" annotation, it won't be narrowed.
|
|
17684
|
-
|
|
17685
|
-
|
|
17862
|
+
const declarations = symbol.getDeclarations();
|
|
17863
|
+
if (declarations.length > maxDeclarationsToUseForInference) {
|
|
17864
|
+
let isExceptionVariable = exceptionTargetSymbolCache.get(symbol.id);
|
|
17865
|
+
if (isExceptionVariable === undefined) {
|
|
17866
|
+
isExceptionVariable = declarations.every((decl) => {
|
|
17867
|
+
if (decl.type !== 1 /* DeclarationType.Variable */) {
|
|
17868
|
+
return false;
|
|
17869
|
+
}
|
|
17870
|
+
const parent = decl.node.parent;
|
|
17871
|
+
return parent?.nodeType === 28 /* ParseNodeType.Except */ && parent.d.name === decl.node;
|
|
17872
|
+
});
|
|
17873
|
+
exceptionTargetSymbolCache.set(symbol.id, isExceptionVariable);
|
|
17874
|
+
}
|
|
17875
|
+
// Exception targets get their types from code flow. Don't let the
|
|
17876
|
+
// declaration-count safeguard turn repeated targets into declared Unknown.
|
|
17877
|
+
if (!isExceptionVariable) {
|
|
17878
|
+
return { type: types_1.UnknownType.create() };
|
|
17879
|
+
}
|
|
17686
17880
|
}
|
|
17687
17881
|
// There was no declaration with a defined type.
|
|
17688
17882
|
return { type: undefined };
|
|
@@ -18312,7 +18506,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
18312
18506
|
if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType,
|
|
18313
18507
|
/* diag */ undefined,
|
|
18314
18508
|
/* constraints */ undefined,
|
|
18315
|
-
/* selfConstraints */ undefined, recursionCount)) {
|
|
18509
|
+
/* selfConstraints */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount)) {
|
|
18316
18510
|
isAssignable = false;
|
|
18317
18511
|
}
|
|
18318
18512
|
}
|
|
@@ -20013,6 +20207,34 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20013
20207
|
return true;
|
|
20014
20208
|
}
|
|
20015
20209
|
}
|
|
20210
|
+
// Determines whether the dest accepts every argument list the source
|
|
20211
|
+
// accepts, apart from parameters that overlap only when omitted.
|
|
20212
|
+
function isParamListOverlapOnlyByOmission(destType, srcType, destParamDetails, srcParamDetails, recursionCount) {
|
|
20213
|
+
if (destParamDetails.params.length !== srcParamDetails.params.length) {
|
|
20214
|
+
return false;
|
|
20215
|
+
}
|
|
20216
|
+
const destScopeIds = (0, typeUtils_1.getTypeVarScopeIds)(destType);
|
|
20217
|
+
const srcScopeIds = (0, typeUtils_1.getTypeVarScopeIds)(srcType);
|
|
20218
|
+
const constraints = new constraintTracker_1.ConstraintTracker();
|
|
20219
|
+
return destParamDetails.params.every((destParam, index) => {
|
|
20220
|
+
const srcParam = srcParamDetails.params[index];
|
|
20221
|
+
if (destParam.kind !== srcParam.kind ||
|
|
20222
|
+
destParam.param.category !== srcParam.param.category ||
|
|
20223
|
+
destParam.param.name !== srcParam.param.name) {
|
|
20224
|
+
return false;
|
|
20225
|
+
}
|
|
20226
|
+
if (destParam.defaultType && srcParam.defaultType) {
|
|
20227
|
+
if ((0, typeUtils_1.isOverlapOnlyByOmission)(destParam.type, destParam.defaultType, srcParam.type)) {
|
|
20228
|
+
return true;
|
|
20229
|
+
}
|
|
20230
|
+
}
|
|
20231
|
+
else if (srcParam.defaultType) {
|
|
20232
|
+
return false;
|
|
20233
|
+
}
|
|
20234
|
+
return assignType((0, typeUtils_1.makeTypeVarsFree)(destParam.type, destScopeIds), (0, typeUtils_1.makeTypeVarsBound)(srcParam.type, srcScopeIds),
|
|
20235
|
+
/* diag */ undefined, constraints, 0 /* AssignTypeFlags.Default */, recursionCount);
|
|
20236
|
+
});
|
|
20237
|
+
}
|
|
20016
20238
|
function assignFunction(destType, srcType, diag, constraints, flags, recursionCount) {
|
|
20017
20239
|
let canAssign = true;
|
|
20018
20240
|
const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipReturnTypeCheck */) === 0;
|
|
@@ -20033,6 +20255,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20033
20255
|
disallowExtraKwargsForTd: (flags & 131072 /* AssignTypeFlags.DisallowExtraKwargsForTd */) !== 0,
|
|
20034
20256
|
});
|
|
20035
20257
|
adjustSourceParamDetailsForDestVariadic(isContra ? destParamDetails : srcParamDetails, isContra ? srcParamDetails : destParamDetails);
|
|
20258
|
+
let paramListOmissionResult;
|
|
20259
|
+
const checkParamListOmission = () => {
|
|
20260
|
+
if (paramListOmissionResult === undefined) {
|
|
20261
|
+
paramListOmissionResult = isParamListOverlapOnlyByOmission(destType, srcType, destParamDetails, srcParamDetails, recursionCount);
|
|
20262
|
+
}
|
|
20263
|
+
return paramListOmissionResult;
|
|
20264
|
+
};
|
|
20036
20265
|
const targetIncludesParamSpec = isContra ? !!srcParamSpec : !!destParamSpec;
|
|
20037
20266
|
const destPositionalCount = destParamDetails.firstKeywordOnlyIndex ?? destParamDetails.params.length;
|
|
20038
20267
|
const srcPositionalCount = srcParamDetails.firstKeywordOnlyIndex ?? srcParamDetails.params.length;
|
|
@@ -20094,6 +20323,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20094
20323
|
// be a match.
|
|
20095
20324
|
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) !== 0) {
|
|
20096
20325
|
if (srcParam.defaultType) {
|
|
20326
|
+
if ((0, typeUtils_1.isOverlapOnlyByOmission)(destParamType, destParam.defaultType, srcParamType) &&
|
|
20327
|
+
checkParamListOmission()) {
|
|
20328
|
+
canAssign = false;
|
|
20329
|
+
}
|
|
20097
20330
|
continue;
|
|
20098
20331
|
}
|
|
20099
20332
|
}
|
|
@@ -20365,6 +20598,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20365
20598
|
// be a match.
|
|
20366
20599
|
if (srcParamInfo.defaultType && destParamInfo.defaultType) {
|
|
20367
20600
|
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) !== 0) {
|
|
20601
|
+
if ((0, typeUtils_1.isOverlapOnlyByOmission)(destParamInfo.type, destParamInfo.defaultType, srcParamType) &&
|
|
20602
|
+
checkParamListOmission()) {
|
|
20603
|
+
canAssign = false;
|
|
20604
|
+
}
|
|
20368
20605
|
destParamMap.delete(srcParamInfo.param.name);
|
|
20369
20606
|
return;
|
|
20370
20607
|
}
|
|
@@ -21198,7 +21435,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21198
21435
|
if (functionType.priv.strippedFirstParamType) {
|
|
21199
21436
|
return functionType;
|
|
21200
21437
|
}
|
|
21201
|
-
if (types_1.FunctionType.isInstanceMethod(functionType)) {
|
|
21438
|
+
if (types_1.FunctionType.isInstanceMethod(functionType) && !treatConstructorAsClassMethod) {
|
|
21202
21439
|
// If the baseType is a metaclass, don't specialize the function.
|
|
21203
21440
|
if ((0, typeUtils_1.isInstantiableMetaclass)(baseType)) {
|
|
21204
21441
|
return functionType;
|
|
@@ -21215,8 +21452,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21215
21452
|
}
|
|
21216
21453
|
return partiallySpecializeBoundMethod(baseType, functionType, diag, recursionCount, selfType ?? baseObj, stripFirstParam);
|
|
21217
21454
|
}
|
|
21218
|
-
if (types_1.FunctionType.isClassMethod(functionType) ||
|
|
21219
|
-
(treatConstructorAsClassMethod && types_1.FunctionType.isConstructorMethod(functionType))) {
|
|
21455
|
+
if (types_1.FunctionType.isClassMethod(functionType) || treatConstructorAsClassMethod) {
|
|
21220
21456
|
const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
|
|
21221
21457
|
const clsType = selfType ? (0, typeUtils_1.convertToInstantiable)(selfType) : undefined;
|
|
21222
21458
|
return partiallySpecializeBoundMethod(baseClass, functionType, diag, recursionCount, clsType ?? baseClass,
|
|
@@ -21580,6 +21816,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21580
21816
|
validateInitSubclassArgs,
|
|
21581
21817
|
isNodeReachable,
|
|
21582
21818
|
isAfterNodeReachable,
|
|
21819
|
+
isKeyPresentInTypedDict: (node) => codeFlowEngine.isKeyPresentInTypedDict(node),
|
|
21583
21820
|
getNodeReachability,
|
|
21584
21821
|
getAfterNodeReachability,
|
|
21585
21822
|
isAsymmetricAccessorAssignment,
|