@zzzen/pyright-internal 1.2.0-dev.20260927 → 1.2.0-dev.20261004
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 -1
- package/dist/analyzer/checker.js +6 -8
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -0
- package/dist/analyzer/codeFlowEngine.js +153 -17
- 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/patternMatching.js +39 -2
- 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/protocols.js +11 -3
- 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 +126 -8
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeUtils.js +9 -1
- 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/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/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/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/typeEvaluator1.test.js +27 -1
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +12 -0
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +28 -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");
|
|
@@ -1835,11 +1836,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1835
1836
|
}
|
|
1836
1837
|
const argList = [];
|
|
1837
1838
|
let previousCategory = 0 /* ArgCategory.Simple */;
|
|
1839
|
+
let hasFakeArg = false;
|
|
1838
1840
|
// Empty arguments do not enter the AST as nodes, but instead are left blank.
|
|
1839
1841
|
// Instead, we detect when we appear to be between two known arguments or at the
|
|
1840
1842
|
// end of the argument list and insert a fake argument of an unknown type to have
|
|
1841
1843
|
// something to match later.
|
|
1842
1844
|
function addFakeArg() {
|
|
1845
|
+
hasFakeArg = true;
|
|
1843
1846
|
argList.push({
|
|
1844
1847
|
argCategory: previousCategory,
|
|
1845
1848
|
typeResult: { type: types_1.UnknownType.create() },
|
|
@@ -1876,7 +1879,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1876
1879
|
/* skipUnknownArgCheck */ true,
|
|
1877
1880
|
/* inferenceContext */ undefined);
|
|
1878
1881
|
});
|
|
1879
|
-
|
|
1882
|
+
let specializedType = type;
|
|
1883
|
+
if (types_1.FunctionType.getParamSpecFromArgsKwargs(type)) {
|
|
1884
|
+
const solution = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints);
|
|
1885
|
+
// The fake argument is used only to identify the active parameter. Preserve
|
|
1886
|
+
// type variables in that parameter while specializing the forwarded ParamSpec.
|
|
1887
|
+
if (hasFakeArg && callResult?.activeParam) {
|
|
1888
|
+
const activeParamIndex = type.shared.parameters.indexOf(callResult.activeParam);
|
|
1889
|
+
if (activeParamIndex >= 0) {
|
|
1890
|
+
(0, typeUtils_1.getTypeVarArgsRecursive)(types_1.FunctionType.getParamType(type, activeParamIndex)).forEach((typeVar) => {
|
|
1891
|
+
if (!(0, types_1.isParamSpec)(typeVar)) {
|
|
1892
|
+
solution.doForEachSolutionSet((solutionSet) => {
|
|
1893
|
+
const solvedType = solutionSet.getType(typeVar);
|
|
1894
|
+
if (!solvedType || (0, types_1.isUnknown)(solvedType)) {
|
|
1895
|
+
solutionSet.setType(typeVar, typeVar);
|
|
1896
|
+
}
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
specializedType = (0, typeUtils_1.applySolvedTypeVars)(type, solution);
|
|
1903
|
+
}
|
|
1880
1904
|
const finalType = (0, types_1.isFunction)(specializedType) ? specializedType : type;
|
|
1881
1905
|
const hasActiveArg = argList.some((arg) => arg.active);
|
|
1882
1906
|
// If the type was specialized (e.g. ParamSpec expansion), the activeParam
|
|
@@ -2725,6 +2749,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2725
2749
|
const memberInfo = (0, typeUtils_1.lookUpClassMember)(classType.classType, nameNode.d.value, 1 /* MemberAccessFlags.SkipOriginalClass */);
|
|
2726
2750
|
if (memberInfo?.isTypeDeclared) {
|
|
2727
2751
|
declaredType = getTypeOfMember(memberInfo);
|
|
2752
|
+
if ((0, symbolNameUtils_1.isMethodExemptFromLsp)(nameValue) &&
|
|
2753
|
+
memberInfo.symbol
|
|
2754
|
+
.getTypedDeclarations()
|
|
2755
|
+
.some((decl) => decl.type === 5 /* DeclarationType.Function */) &&
|
|
2756
|
+
(0, types_1.isFunctionOrOverloaded)(typeResult.type) &&
|
|
2757
|
+
(0, types_1.isFunctionOrOverloaded)(declaredType) &&
|
|
2758
|
+
!isFinalVariable(memberInfo.symbol)) {
|
|
2759
|
+
const baseMethods = (0, types_1.isFunction)(declaredType)
|
|
2760
|
+
? [declaredType]
|
|
2761
|
+
: [
|
|
2762
|
+
...types_1.OverloadedType.getOverloads(declaredType),
|
|
2763
|
+
types_1.OverloadedType.getImplementation(declaredType),
|
|
2764
|
+
];
|
|
2765
|
+
if (!baseMethods.some((method) => method && (0, types_1.isFunction)(method) && types_1.FunctionType.isFinal(method))) {
|
|
2766
|
+
// Apply the same override exemptions to aliases and method definitions.
|
|
2767
|
+
declaredType = undefined;
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2728
2770
|
}
|
|
2729
2771
|
}
|
|
2730
2772
|
}
|
|
@@ -4570,6 +4612,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4570
4612
|
const isAccessedThroughObject = types_1.TypeBase.isInstance(classType);
|
|
4571
4613
|
// Always look for a member with a declared type first.
|
|
4572
4614
|
let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, flags | 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
|
4615
|
+
// A class-level method alias retains its inferred signature, unlike an annotated variable.
|
|
4616
|
+
if (usage.method === 'get' &&
|
|
4617
|
+
memberInfo?.skippedUndeclaredType &&
|
|
4618
|
+
memberInfo.symbol.getTypedDeclarations().some((decl) => decl.type === 5 /* DeclarationType.Function */)) {
|
|
4619
|
+
const inferredMember = (0, typeUtils_1.lookUpClassMember)(classType, memberName, flags);
|
|
4620
|
+
if (inferredMember?.isClassMember &&
|
|
4621
|
+
!inferredMember.isInstanceMember &&
|
|
4622
|
+
(0, types_1.isFunctionOrOverloaded)(getTypeOfMember(inferredMember))) {
|
|
4623
|
+
memberInfo = inferredMember;
|
|
4624
|
+
}
|
|
4625
|
+
}
|
|
4573
4626
|
// If we couldn't find a symbol with a declared type, use
|
|
4574
4627
|
// a symbol with an inferred type.
|
|
4575
4628
|
if (!memberInfo) {
|
|
@@ -4818,7 +4871,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4818
4871
|
const subDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
|
4819
4872
|
const methodTypeResult = getTypeOfBoundMember(errorNode, concreteMemberType, accessMethodName,
|
|
4820
4873
|
/* usage */ undefined, subDiag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */);
|
|
4821
|
-
|
|
4874
|
+
const deferredMethodType = usage.method === 'get'
|
|
4875
|
+
? getDescriptorGetMethodWithDeferredSelfSpecialization(concreteMemberType, subDiag)
|
|
4876
|
+
: undefined;
|
|
4877
|
+
if ((!methodTypeResult || methodTypeResult.typeErrors) && !deferredMethodType) {
|
|
4822
4878
|
// Provide special error messages for properties.
|
|
4823
4879
|
if (types_1.ClassType.isPropertyClass(concreteMemberType) && usage.method !== 'get') {
|
|
4824
4880
|
const message = usage.method === 'set' ? localize_1.LocAddendum.propertyMissingSetter() : localize_1.LocAddendum.propertyMissingDeleter();
|
|
@@ -4830,9 +4886,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4830
4886
|
}
|
|
4831
4887
|
return { type: memberType };
|
|
4832
4888
|
}
|
|
4833
|
-
const methodClassType = methodTypeResult
|
|
4834
|
-
let methodType = methodTypeResult.type;
|
|
4835
|
-
if (
|
|
4889
|
+
const methodClassType = methodTypeResult?.classType ?? concreteMemberType;
|
|
4890
|
+
let methodType = deferredMethodType ?? methodTypeResult.type;
|
|
4891
|
+
if (!methodClassType) {
|
|
4836
4892
|
if (diag && subDiag) {
|
|
4837
4893
|
diag.addAddendum(subDiag);
|
|
4838
4894
|
}
|
|
@@ -4993,6 +5049,65 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4993
5049
|
memberAccessDeprecationInfo: deprecationInfo,
|
|
4994
5050
|
};
|
|
4995
5051
|
}
|
|
5052
|
+
function getDescriptorGetMethodWithDeferredSelfSpecialization(concreteMemberType, diag) {
|
|
5053
|
+
const member = (0, typeUtils_1.lookUpClassMember)(concreteMemberType, '__get__');
|
|
5054
|
+
if (!member || !(0, types_1.isInstantiableClass)(member.unspecializedClassType)) {
|
|
5055
|
+
return undefined;
|
|
5056
|
+
}
|
|
5057
|
+
const unspecializedClassType = member.unspecializedClassType;
|
|
5058
|
+
const declaringClassType = member.classType;
|
|
5059
|
+
if (!(0, types_1.isInstantiableClass)(declaringClassType)) {
|
|
5060
|
+
return undefined;
|
|
5061
|
+
}
|
|
5062
|
+
const declaringObjectType = types_1.ClassType.cloneAsInstance(declaringClassType);
|
|
5063
|
+
const unspecializedMethodType = getEffectiveTypeOfSymbol(member.symbol);
|
|
5064
|
+
if (!(0, types_1.isFunctionOrOverloaded)(unspecializedMethodType)) {
|
|
5065
|
+
return undefined;
|
|
5066
|
+
}
|
|
5067
|
+
// A class ParamSpec used in Concatenate within the self annotation needs to be
|
|
5068
|
+
// solved from the concrete descriptor, rather than specialized before self is bound.
|
|
5069
|
+
const classParamSpecs = types_1.ClassType.getTypeParams(unspecializedClassType).filter(types_1.isParamSpec);
|
|
5070
|
+
if (classParamSpecs.length === 0) {
|
|
5071
|
+
return undefined;
|
|
5072
|
+
}
|
|
5073
|
+
const signatures = (0, types_1.isFunction)(unspecializedMethodType)
|
|
5074
|
+
? [unspecializedMethodType]
|
|
5075
|
+
: types_1.OverloadedType.getOverloads(unspecializedMethodType);
|
|
5076
|
+
const shouldDefer = signatures.some((signature) => {
|
|
5077
|
+
if (signature.shared.parameters.length === 0) {
|
|
5078
|
+
return false;
|
|
5079
|
+
}
|
|
5080
|
+
const selfParamType = types_1.FunctionType.getParamType(signature, 0);
|
|
5081
|
+
if (!(0, types_1.isClassInstance)(selfParamType) || !types_1.ClassType.isSameGenericClass(selfParamType, declaringObjectType)) {
|
|
5082
|
+
return false;
|
|
5083
|
+
}
|
|
5084
|
+
class ConcatenateParamSpecWalker extends typeWalker_1.TypeWalker {
|
|
5085
|
+
constructor() {
|
|
5086
|
+
super(...arguments);
|
|
5087
|
+
this.found = false;
|
|
5088
|
+
}
|
|
5089
|
+
visitFunction(type) {
|
|
5090
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
|
5091
|
+
if (paramSpec &&
|
|
5092
|
+
types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type).shared.parameters.length > 0 &&
|
|
5093
|
+
classParamSpecs.some((classParamSpec) => (0, types_1.isTypeSame)(paramSpec, classParamSpec))) {
|
|
5094
|
+
this.found = true;
|
|
5095
|
+
this.cancelWalk();
|
|
5096
|
+
return;
|
|
5097
|
+
}
|
|
5098
|
+
super.visitFunction(type);
|
|
5099
|
+
}
|
|
5100
|
+
}
|
|
5101
|
+
const walker = new ConcatenateParamSpecWalker();
|
|
5102
|
+
selfParamType.priv.typeArgs?.forEach((typeArg) => walker.walk(typeArg));
|
|
5103
|
+
return walker.found;
|
|
5104
|
+
});
|
|
5105
|
+
if (!shouldDefer) {
|
|
5106
|
+
return undefined;
|
|
5107
|
+
}
|
|
5108
|
+
return bindFunctionToClassOrObject(declaringObjectType, unspecializedMethodType, declaringClassType,
|
|
5109
|
+
/* treatConstructorAsClassMethod */ false, concreteMemberType, diag);
|
|
5110
|
+
}
|
|
4996
5111
|
function bindMethodForMemberAccess(type, concreteType, memberInfo, classType, selfType, flags, memberName, usage, diag, recursionCount = 0) {
|
|
4997
5112
|
// Check for an attempt to overwrite a final method.
|
|
4998
5113
|
if (usage.method === 'set') {
|
|
@@ -13442,6 +13557,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13442
13557
|
// Determine the effective metaclass.
|
|
13443
13558
|
if (metaclassNode) {
|
|
13444
13559
|
let metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
|
|
13560
|
+
if ((0, types_1.isAny)(metaclassType)) {
|
|
13561
|
+
metaclassType = types_1.UnknownType.create();
|
|
13562
|
+
}
|
|
13445
13563
|
if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
|
|
13446
13564
|
if ((0, typeUtils_1.requiresSpecialization)(metaclassType, { ignorePseudoGeneric: true })) {
|
|
13447
13565
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.metaclassIsGeneric(), metaclassNode);
|
|
@@ -21198,7 +21316,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21198
21316
|
if (functionType.priv.strippedFirstParamType) {
|
|
21199
21317
|
return functionType;
|
|
21200
21318
|
}
|
|
21201
|
-
if (types_1.FunctionType.isInstanceMethod(functionType)) {
|
|
21319
|
+
if (types_1.FunctionType.isInstanceMethod(functionType) && !treatConstructorAsClassMethod) {
|
|
21202
21320
|
// If the baseType is a metaclass, don't specialize the function.
|
|
21203
21321
|
if ((0, typeUtils_1.isInstantiableMetaclass)(baseType)) {
|
|
21204
21322
|
return functionType;
|
|
@@ -21215,8 +21333,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21215
21333
|
}
|
|
21216
21334
|
return partiallySpecializeBoundMethod(baseType, functionType, diag, recursionCount, selfType ?? baseObj, stripFirstParam);
|
|
21217
21335
|
}
|
|
21218
|
-
if (types_1.FunctionType.isClassMethod(functionType) ||
|
|
21219
|
-
(treatConstructorAsClassMethod && types_1.FunctionType.isConstructorMethod(functionType))) {
|
|
21336
|
+
if (types_1.FunctionType.isClassMethod(functionType) || treatConstructorAsClassMethod) {
|
|
21220
21337
|
const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
|
|
21221
21338
|
const clsType = selfType ? (0, typeUtils_1.convertToInstantiable)(selfType) : undefined;
|
|
21222
21339
|
return partiallySpecializeBoundMethod(baseClass, functionType, diag, recursionCount, clsType ?? baseClass,
|
|
@@ -21580,6 +21697,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21580
21697
|
validateInitSubclassArgs,
|
|
21581
21698
|
isNodeReachable,
|
|
21582
21699
|
isAfterNodeReachable,
|
|
21700
|
+
isKeyPresentInTypedDict: (node) => codeFlowEngine.isKeyPresentInTypedDict(node),
|
|
21583
21701
|
getNodeReachability,
|
|
21584
21702
|
getAfterNodeReachability,
|
|
21585
21703
|
isAsymmetricAccessorAssignment,
|