@zzzen/pyright-internal 1.2.0-dev.20241027 → 1.2.0-dev.20241110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/binder.d.ts +2 -3
- package/dist/analyzer/binder.js +36 -21
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +11 -7
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +2 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +18 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +1 -1
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +0 -4
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -1
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/enums.js +3 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/importResolver.js +5 -5
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +6 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +2 -0
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +4 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +1 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/serviceUtils.d.ts +0 -2
- package/dist/analyzer/serviceUtils.js +3 -5
- package/dist/analyzer/serviceUtils.js.map +1 -1
- package/dist/analyzer/sourceFile.js +1 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +2 -2
- package/dist/analyzer/typeEvaluator.js +153 -43
- 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/typeGuards.js +10 -5
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +6 -0
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +0 -1
- package/dist/analyzer/typeUtils.js +51 -30
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +2 -1
- package/dist/analyzer/typedDicts.js +21 -1
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.js +4 -5
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/pathConsts.d.ts +3 -0
- package/dist/common/pathConsts.js +4 -1
- package/dist/common/pathConsts.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +6 -2
- package/dist/languageService/autoImporter.js +15 -15
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.js +4 -2
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +33 -10
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +21 -13
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +5 -4
- package/dist/localization/localize.js +5 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -2
- package/dist/localization/package.nls.de.json +2 -3
- package/dist/localization/package.nls.en-us.json +19 -4
- package/dist/localization/package.nls.es.json +2 -3
- package/dist/localization/package.nls.fr.json +1 -2
- package/dist/localization/package.nls.it.json +2 -3
- package/dist/localization/package.nls.ja.json +1 -2
- package/dist/localization/package.nls.ko.json +1 -2
- package/dist/localization/package.nls.pl.json +1 -2
- package/dist/localization/package.nls.pt-br.json +1 -2
- package/dist/localization/package.nls.qps-ploc.json +1 -2
- package/dist/localization/package.nls.ru.json +1 -2
- package/dist/localization/package.nls.tr.json +1 -2
- package/dist/localization/package.nls.zh-cn.json +1 -2
- package/dist/localization/package.nls.zh-tw.json +1 -2
- package/dist/parser/parseNodes.d.ts +3 -2
- package/dist/parser/parseNodes.js +2 -1
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +2 -1
- package/dist/parser/parser.js +36 -7
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/fourslash/hover.typedDict.get.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.typedDict.get.fourslash.js +16 -0
- package/dist/tests/fourslash/hover.typedDict.get.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js +73 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.js +14 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +6 -2
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +7 -1
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +17 -1
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +13 -3
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +4 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/package.json +1 -1
@@ -893,6 +893,9 @@ function selfSpecializeClass(type, options) {
|
|
893
893
|
return type;
|
894
894
|
}
|
895
895
|
const typeParams = type.shared.typeParams.map((typeParam) => {
|
896
|
+
if ((0, types_1.isTypeVarTuple)(typeParam)) {
|
897
|
+
typeParam = types_1.TypeVarType.cloneForUnpacked(typeParam);
|
898
|
+
}
|
896
899
|
return (options === null || options === void 0 ? void 0 : options.useBoundTypeVars) ? types_1.TypeVarType.cloneAsBound(typeParam) : typeParam;
|
897
900
|
});
|
898
901
|
return types_1.ClassType.specialize(type, typeParams);
|
@@ -1331,7 +1334,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1331
1334
|
let classFlags = 0 /* ClassIteratorFlags.Default */;
|
1332
1335
|
if (flags & 1 /* MemberAccessFlags.SkipOriginalClass */) {
|
1333
1336
|
if ((0, types_1.isClass)(classType)) {
|
1334
|
-
skipMroClass = classType;
|
1337
|
+
skipMroClass = (0, types_1.isClassInstance)(classType) ? types_1.ClassType.cloneAsInstantiable(classType) : classType;
|
1335
1338
|
}
|
1336
1339
|
}
|
1337
1340
|
if (flags & 2 /* MemberAccessFlags.SkipBaseClasses */) {
|
@@ -1418,7 +1421,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1418
1421
|
// Handle the special case of a __call__ class member in a partial class.
|
1419
1422
|
if (memberName === '__call__' &&
|
1420
1423
|
classType.priv.partialCallType &&
|
1421
|
-
types_1.ClassType.isSameGenericClass(classType, specializedMroClass)) {
|
1424
|
+
types_1.ClassType.isSameGenericClass(types_1.TypeBase.isInstance(classType) ? types_1.ClassType.cloneAsInstantiable(classType) : classType, specializedMroClass)) {
|
1422
1425
|
symbol = symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, classType.priv.partialCallType);
|
1423
1426
|
}
|
1424
1427
|
const cm = {
|
@@ -1592,6 +1595,10 @@ function getTypeVarArgsRecursive(type, recursionCount = 0) {
|
|
1592
1595
|
if (type.shared.recursiveAlias) {
|
1593
1596
|
return [];
|
1594
1597
|
}
|
1598
|
+
// Don't return any bound type variables.
|
1599
|
+
if (types_1.TypeVarType.isBound(type)) {
|
1600
|
+
return [];
|
1601
|
+
}
|
1595
1602
|
// Don't return any P.args or P.kwargs types.
|
1596
1603
|
if ((0, types_1.isParamSpec)(type) && type.priv.paramSpecAccess) {
|
1597
1604
|
return [types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined)];
|
@@ -1631,15 +1638,13 @@ function getTypeVarArgsRecursive(type, recursionCount = 0) {
|
|
1631
1638
|
// Creates a specialized version of the class, filling in any unspecified
|
1632
1639
|
// type arguments with Unknown or default value.
|
1633
1640
|
function specializeWithDefaultTypeArgs(type) {
|
1634
|
-
if (type.shared.typeParams.length === 0 || type.priv.typeArgs) {
|
1641
|
+
if (type.shared.typeParams.length === 0 || type.priv.typeArgs || !type.shared.typeVarScopeId) {
|
1635
1642
|
return type;
|
1636
1643
|
}
|
1637
1644
|
const solution = new constraintSolution_1.ConstraintSolution();
|
1638
|
-
|
1639
|
-
|
1640
|
-
solution.setType(typeParam, applySolvedTypeVars(typeParam.shared.defaultType, solution));
|
1645
|
+
return applySolvedTypeVars(type, solution, {
|
1646
|
+
replaceUnsolved: { scopeIds: [type.shared.typeVarScopeId], tupleClassType: undefined },
|
1641
1647
|
});
|
1642
|
-
return applySolvedTypeVars(type, solution);
|
1643
1648
|
}
|
1644
1649
|
// Builds a mapping between type parameters and their specialized
|
1645
1650
|
// types. For example, if the generic type is Dict[_T1, _T2] and the
|
@@ -2871,6 +2876,7 @@ class TypeVarTransformer {
|
|
2871
2876
|
let newTypeArgs;
|
2872
2877
|
let newTupleTypeArgs;
|
2873
2878
|
let specializationNeeded = false;
|
2879
|
+
let isTypeArgExplicit = true;
|
2874
2880
|
// If type args were previously provided, specialize them.
|
2875
2881
|
// Handle tuples specially.
|
2876
2882
|
if (types_1.ClassType.isTupleClass(classType)) {
|
@@ -2916,6 +2922,7 @@ class TypeVarTransformer {
|
|
2916
2922
|
const newTypeArgType = this.apply(typeParams[0], recursionCount);
|
2917
2923
|
newTupleTypeArgs = [{ type: newTypeArgType, isUnbounded: true }];
|
2918
2924
|
specializationNeeded = true;
|
2925
|
+
isTypeArgExplicit = false;
|
2919
2926
|
}
|
2920
2927
|
}
|
2921
2928
|
// If this is an empty tuple, don't recompute the non-tuple type argument.
|
@@ -2926,6 +2933,9 @@ class TypeVarTransformer {
|
|
2926
2933
|
}
|
2927
2934
|
if (!newTypeArgs) {
|
2928
2935
|
const typeArgs = (_a = classType.priv.typeArgs) !== null && _a !== void 0 ? _a : typeParams;
|
2936
|
+
if (!classType.priv.typeArgs) {
|
2937
|
+
isTypeArgExplicit = false;
|
2938
|
+
}
|
2929
2939
|
newTypeArgs = typeArgs.map((oldTypeArgType) => {
|
2930
2940
|
let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
|
2931
2941
|
if (newTypeArgType !== oldTypeArgType) {
|
@@ -2943,8 +2953,7 @@ class TypeVarTransformer {
|
|
2943
2953
|
if (!specializationNeeded) {
|
2944
2954
|
return classType;
|
2945
2955
|
}
|
2946
|
-
return types_1.ClassType.specialize(classType, newTypeArgs,
|
2947
|
-
/* isTypeArgExplicit */ true,
|
2956
|
+
return types_1.ClassType.specialize(classType, newTypeArgs, isTypeArgExplicit,
|
2948
2957
|
/* includeSubclasses */ undefined, newTupleTypeArgs);
|
2949
2958
|
}
|
2950
2959
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
@@ -3300,32 +3309,44 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3300
3309
|
return getUnknownForTypeVar(typeVar, (_c = this._options.replaceUnsolved) === null || _c === void 0 ? void 0 : _c.tupleClassType);
|
3301
3310
|
}
|
3302
3311
|
transformUnionSubtype(preTransform, postTransform) {
|
3303
|
-
var _a, _b;
|
3312
|
+
var _a, _b, _c;
|
3304
3313
|
// If a union contains unsolved TypeVars within scope, eliminate them
|
3305
3314
|
// unless this results in an empty union. This elimination is needed
|
3306
3315
|
// in cases where TypeVars can go unsolved due to unions in parameter
|
3307
3316
|
// annotations, like this:
|
3308
3317
|
// def test(x: Union[str, T]) -> Union[str, T]
|
3309
|
-
if ((_a = this._options.replaceUnsolved) === null || _a === void 0 ? void 0 : _a.eliminateUnsolvedInUnions) {
|
3310
|
-
|
3311
|
-
|
3312
|
-
|
3313
|
-
|
3314
|
-
|
3315
|
-
|
3316
|
-
|
3317
|
-
|
3318
|
-
|
3319
|
-
|
3320
|
-
|
3321
|
-
|
3322
|
-
|
3323
|
-
|
3324
|
-
|
3325
|
-
|
3326
|
-
|
3327
|
-
|
3328
|
-
|
3318
|
+
if (!((_a = this._options.replaceUnsolved) === null || _a === void 0 ? void 0 : _a.eliminateUnsolvedInUnions)) {
|
3319
|
+
return postTransform;
|
3320
|
+
}
|
3321
|
+
const solutionSet = this._solution.getSolutionSet((_b = this._activeConstraintSetIndex) !== null && _b !== void 0 ? _b : 0);
|
3322
|
+
if ((0, types_1.isTypeVar)(preTransform)) {
|
3323
|
+
if (!this._shouldReplaceTypeVar(preTransform) || !this._shouldReplaceUnsolvedTypeVar(preTransform)) {
|
3324
|
+
return postTransform;
|
3325
|
+
}
|
3326
|
+
const typeVarType = solutionSet.getType(preTransform);
|
3327
|
+
// Did the TypeVar remain unsolved?
|
3328
|
+
if (typeVarType) {
|
3329
|
+
if (!(0, types_1.isTypeVar)(typeVarType) || !types_1.TypeVarType.isUnification(typeVarType)) {
|
3330
|
+
return postTransform;
|
3331
|
+
}
|
3332
|
+
}
|
3333
|
+
// If the TypeVar was not transformed, then it was unsolved,
|
3334
|
+
// and we'll eliminate it.
|
3335
|
+
if (preTransform === postTransform) {
|
3336
|
+
return undefined;
|
3337
|
+
}
|
3338
|
+
// If useDefaultForUnsolved or useUnknownForUnsolved is true, the postTransform type will
|
3339
|
+
// be Unknown, which we want to eliminate.
|
3340
|
+
if (this._options.replaceUnsolved && (0, types_1.isUnknown)(postTransform)) {
|
3341
|
+
return undefined;
|
3342
|
+
}
|
3343
|
+
}
|
3344
|
+
else if ((_c = preTransform.props) === null || _c === void 0 ? void 0 : _c.condition) {
|
3345
|
+
// If this is a type that is conditioned on a unification TypeVar,
|
3346
|
+
// see if TypeVar was solved. If not, eliminate the type.
|
3347
|
+
for (const condition of preTransform.props.condition) {
|
3348
|
+
if (types_1.TypeVarType.isUnification(condition.typeVar) && !solutionSet.getType(condition.typeVar)) {
|
3349
|
+
return undefined;
|
3329
3350
|
}
|
3330
3351
|
}
|
3331
3352
|
}
|