@zzzen/pyright-internal 1.2.0-dev.20230903 → 1.2.0-dev.20230917
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 +1 -0
- package/dist/analyzer/binder.js +8 -4
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +81 -43
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +6 -0
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +16 -7
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +14 -2
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +25 -3
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/importResolver.js +4 -7
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.js +2 -2
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +2 -0
- package/dist/analyzer/parameterUtils.js +53 -1
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parentDirectoryCache.js +1 -1
- package/dist/analyzer/parentDirectoryCache.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -0
- package/dist/analyzer/parseTreeUtils.js +16 -2
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +39 -22
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -2
- package/dist/analyzer/program.js +30 -24
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +10 -8
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.js +14 -12
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeEvaluator.js +223 -163
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +12 -10
- package/dist/analyzer/typeEvaluatorTypes.js +11 -8
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +9 -0
- package/dist/analyzer/typeGuards.js +60 -7
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +3 -2
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +6 -4
- package/dist/analyzer/typeUtils.js +98 -58
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +5 -5
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +1 -0
- package/dist/analyzer/types.js +11 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.js +2 -2
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +6 -0
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/pathUtils.d.ts +2 -15
- package/dist/common/pathUtils.js +9 -84
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +26 -12
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/languageServerBase.d.ts +1 -1
- package/dist/languageServerBase.js +2 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +3 -2
- package/dist/languageService/completionProvider.js +12 -6
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +17 -4
- package/dist/localization/localize.js +10 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +8 -4
- package/dist/localization/package.nls.de.json +8 -4
- package/dist/localization/package.nls.en-us.json +12 -5
- package/dist/localization/package.nls.es.json +8 -4
- package/dist/localization/package.nls.fr.json +8 -4
- package/dist/localization/package.nls.it.json +8 -4
- package/dist/localization/package.nls.ja.json +8 -4
- package/dist/localization/package.nls.ko.json +8 -4
- package/dist/localization/package.nls.pl.json +8 -4
- package/dist/localization/package.nls.pt-br.json +8 -4
- package/dist/localization/package.nls.qps-ploc.json +8 -4
- package/dist/localization/package.nls.ru.json +8 -4
- package/dist/localization/package.nls.tr.json +8 -4
- package/dist/localization/package.nls.zh-cn.json +8 -4
- package/dist/localization/package.nls.zh-tw.json +8 -4
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/checker.test.js +2 -2
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/completions.test.js +27 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +5 -5
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js +5 -5
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +11 -9
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +14 -14
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js +12 -12
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +9 -9
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js +3 -3
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +3 -3
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +4 -4
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -1
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js +8 -8
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +1 -0
- package/dist/tests/fourslash/importnotresolved.fourslash.js +2 -2
- package/dist/tests/fourslash/importnotresolved.fourslash.js.map +1 -1
- package/dist/tests/fourslash/missingModuleSource.fourslash.js +1 -1
- package/dist/tests/fourslash/missingModuleSource.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
- package/dist/tests/harness/fourslash/testState.Consts.js +2 -0
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +4 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +10 -6
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/pathUtils.test.js +13 -21
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +1 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +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 +8 -4
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/workspaceFactory.js +8 -14
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
package/dist/analyzer/checker.js
CHANGED
@@ -1105,15 +1105,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1105
1105
|
}
|
1106
1106
|
const exprTypeResult = this._evaluator.getTypeOfExpression(expression);
|
1107
1107
|
let isExprFunction = true;
|
1108
|
+
let isCoroutine = false;
|
1108
1109
|
(0, typeUtils_1.doForEachSubtype)(exprTypeResult.type, (subtype) => {
|
1109
1110
|
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
1110
1111
|
if (!(0, types_1.isFunction)(subtype) && !(0, types_1.isOverloadedFunction)(subtype)) {
|
1111
1112
|
isExprFunction = false;
|
1112
1113
|
}
|
1114
|
+
if ((0, types_1.isClassInstance)(subtype) && types_1.ClassType.isBuiltIn(subtype, 'Coroutine')) {
|
1115
|
+
isCoroutine = true;
|
1116
|
+
}
|
1113
1117
|
});
|
1114
1118
|
if (isExprFunction) {
|
1115
1119
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnnecessaryComparison, diagnosticRules_1.DiagnosticRule.reportUnnecessaryComparison, localize_1.Localizer.Diagnostic.functionInConditionalExpression(), expression);
|
1116
1120
|
}
|
1121
|
+
if (isCoroutine) {
|
1122
|
+
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnnecessaryComparison, diagnosticRules_1.DiagnosticRule.reportUnnecessaryComparison, localize_1.Localizer.Diagnostic.coroutineInConditionalExpression(), expression);
|
1123
|
+
}
|
1117
1124
|
}
|
1118
1125
|
_reportUnusedExpression(node) {
|
1119
1126
|
var _a, _b;
|
@@ -1890,14 +1897,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1890
1897
|
// There should never be a single overload.
|
1891
1898
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.singleOverload().format({ name }), primaryDecl.node.name);
|
1892
1899
|
}
|
1893
|
-
overloadedFunctions.forEach((overload) => {
|
1894
|
-
if (overload.details.declaration &&
|
1895
|
-
!ParseTreeUtils.isFunctionSuiteEmpty(overload.details.declaration.node)) {
|
1896
|
-
const diag = new diagnostic_1.DiagnosticAddendum();
|
1897
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overloadWithImplementation());
|
1898
|
-
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.overloadWithImplementation().format({ name }) + diag.getString(), overload.details.declaration.node.name);
|
1899
|
-
}
|
1900
|
-
});
|
1901
1900
|
// If the file is not a stub and this is the first overload,
|
1902
1901
|
// verify that there is an implementation.
|
1903
1902
|
if (!this._fileInfo.isStubFile && overloadedFunctions.length > 0) {
|
@@ -1990,18 +1989,24 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1990
1989
|
// is implicitly initialized by the synthesized `__init__` method and
|
1991
1990
|
// therefore has an implied assignment.
|
1992
1991
|
let isImplicitlyAssigned = false;
|
1992
|
+
// Is this a class variable within a protocol class? If so, it can
|
1993
|
+
// be marked final without providing a value.
|
1994
|
+
let isProtocolClass = false;
|
1993
1995
|
if (symbol.isClassMember() && !symbol.isClassVar()) {
|
1994
1996
|
const containingClass = ParseTreeUtils.getEnclosingClass(firstDecl.node, /* stopAtFunction */ true);
|
1995
1997
|
if (containingClass) {
|
1996
1998
|
const classType = this._evaluator.getTypeOfClass(containingClass);
|
1997
|
-
if (classType &&
|
1998
|
-
(
|
1999
|
-
|
2000
|
-
|
1999
|
+
if (classType && (0, types_1.isClass)(classType.decoratedType)) {
|
2000
|
+
if (types_1.ClassType.isDataClass(classType.decoratedType)) {
|
2001
|
+
isImplicitlyAssigned = true;
|
2002
|
+
}
|
2003
|
+
if (types_1.ClassType.isProtocolClass(classType.decoratedType)) {
|
2004
|
+
isProtocolClass = true;
|
2005
|
+
}
|
2001
2006
|
}
|
2002
2007
|
}
|
2003
2008
|
}
|
2004
|
-
if (!isImplicitlyAssigned) {
|
2009
|
+
if (!isImplicitlyAssigned && !isProtocolClass) {
|
2005
2010
|
this._evaluator.addError(localize_1.Localizer.Diagnostic.finalUnassigned().format({ name }), firstDecl.node);
|
2006
2011
|
}
|
2007
2012
|
}
|
@@ -2492,7 +2497,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2492
2497
|
// derives from an unknown type. In this case, we'll add an
|
2493
2498
|
// unknown type into the filtered type list to avoid any
|
2494
2499
|
// false positives.
|
2495
|
-
const isClassRelationshipIndeterminate =
|
2500
|
+
const isClassRelationshipIndeterminate = filterIsSuperclass && filterIsSubclass && !types_1.ClassType.isSameGenericClass(varType, filterType);
|
2496
2501
|
if (isClassRelationshipIndeterminate) {
|
2497
2502
|
filteredTypes.push(types_1.UnknownType.create());
|
2498
2503
|
}
|
@@ -2628,34 +2633,55 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2628
2633
|
}
|
2629
2634
|
let errorMessage;
|
2630
2635
|
let deprecatedMessage;
|
2636
|
+
function getDeprecatedMessageForFunction(functionType) {
|
2637
|
+
if (functionType.details.declaration &&
|
2638
|
+
functionType.details.declaration.node.nodeType === 28 /* Function */) {
|
2639
|
+
const containingClass = ParseTreeUtils.getEnclosingClass(functionType.details.declaration.node,
|
2640
|
+
/* stopAtFunction */ true);
|
2641
|
+
if (containingClass) {
|
2642
|
+
return localize_1.Localizer.Diagnostic.deprecatedMethod().format({
|
2643
|
+
name: functionType.details.name || '<anonymous>',
|
2644
|
+
className: containingClass.name.value,
|
2645
|
+
});
|
2646
|
+
}
|
2647
|
+
}
|
2648
|
+
return localize_1.Localizer.Diagnostic.deprecatedFunction().format({
|
2649
|
+
name: functionType.details.name,
|
2650
|
+
});
|
2651
|
+
}
|
2631
2652
|
function getDeprecatedMessageForOverloadedCall(evaluator, type) {
|
2632
2653
|
// Determine if the node is part of a call expression. If so,
|
2633
2654
|
// we can determine which overload(s) were used to satisfy
|
2634
2655
|
// the call expression and determine whether any of them
|
2635
2656
|
// are deprecated.
|
2657
|
+
let callTypeResult;
|
2636
2658
|
const callNode = ParseTreeUtils.getCallForName(node);
|
2637
2659
|
if (callNode) {
|
2638
|
-
|
2639
|
-
|
2640
|
-
|
2641
|
-
|
2642
|
-
|
2643
|
-
|
2644
|
-
|
2645
|
-
|
2646
|
-
|
2647
|
-
|
2648
|
-
|
2649
|
-
|
2650
|
-
|
2651
|
-
|
2652
|
-
|
2653
|
-
|
2654
|
-
});
|
2655
|
-
}
|
2660
|
+
callTypeResult = evaluator.getTypeResult(callNode);
|
2661
|
+
}
|
2662
|
+
else {
|
2663
|
+
const decoratorNode = ParseTreeUtils.getDecoratorForName(node);
|
2664
|
+
if (decoratorNode) {
|
2665
|
+
callTypeResult = evaluator.getTypeResultForDecorator(decoratorNode);
|
2666
|
+
}
|
2667
|
+
}
|
2668
|
+
if (callTypeResult &&
|
2669
|
+
callTypeResult.overloadsUsedForCall &&
|
2670
|
+
callTypeResult.overloadsUsedForCall.length > 0) {
|
2671
|
+
callTypeResult.overloadsUsedForCall.forEach((overload) => {
|
2672
|
+
if (overload.details.deprecatedMessage !== undefined) {
|
2673
|
+
if (node.value === overload.details.name) {
|
2674
|
+
deprecatedMessage = overload.details.deprecatedMessage;
|
2675
|
+
errorMessage = getDeprecatedMessageForFunction(overload);
|
2656
2676
|
}
|
2657
|
-
|
2658
|
-
|
2677
|
+
else if ((0, types_1.isInstantiableClass)(type) && overload.details.name === '__init__') {
|
2678
|
+
deprecatedMessage = overload.details.deprecatedMessage;
|
2679
|
+
errorMessage = localize_1.Localizer.Diagnostic.deprecatedConstructor().format({
|
2680
|
+
name: type.details.name,
|
2681
|
+
});
|
2682
|
+
}
|
2683
|
+
}
|
2684
|
+
});
|
2659
2685
|
}
|
2660
2686
|
}
|
2661
2687
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
@@ -2672,11 +2698,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2672
2698
|
}
|
2673
2699
|
}
|
2674
2700
|
else if ((0, types_1.isFunction)(subtype)) {
|
2675
|
-
if (subtype.details.deprecatedMessage !== undefined
|
2676
|
-
|
2677
|
-
|
2678
|
-
|
2679
|
-
}
|
2701
|
+
if (subtype.details.deprecatedMessage !== undefined) {
|
2702
|
+
if (!subtype.details.name || node.value === subtype.details.name) {
|
2703
|
+
deprecatedMessage = subtype.details.deprecatedMessage;
|
2704
|
+
errorMessage = getDeprecatedMessageForFunction(subtype);
|
2705
|
+
}
|
2680
2706
|
}
|
2681
2707
|
}
|
2682
2708
|
else if ((0, types_1.isOverloadedFunction)(subtype)) {
|
@@ -3178,7 +3204,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3178
3204
|
if (!types_1.ClassType.isDataClass(classType)) {
|
3179
3205
|
return;
|
3180
3206
|
}
|
3181
|
-
const postInitMember = (0, typeUtils_1.lookUpClassMember)(classType, '__post_init__', 2 /* SkipBaseClasses */ |
|
3207
|
+
const postInitMember = (0, typeUtils_1.lookUpClassMember)(classType, '__post_init__', 2 /* SkipBaseClasses */ | 32 /* DeclaredTypesOnly */);
|
3182
3208
|
// If there's no __post_init__ method, there's nothing to check.
|
3183
3209
|
if (!postInitMember) {
|
3184
3210
|
return;
|
@@ -3508,7 +3534,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3508
3534
|
// __call__ method, skip this check.
|
3509
3535
|
const metaclass = newMember.classType.details.effectiveMetaclass;
|
3510
3536
|
if (metaclass && (0, types_1.isClass)(metaclass) && !types_1.ClassType.isBuiltIn(metaclass, 'type')) {
|
3511
|
-
const callMethod = (0, typeUtils_1.lookUpClassMember)(metaclass, '__call__',
|
3537
|
+
const callMethod = (0, typeUtils_1.lookUpClassMember)(metaclass, '__call__', 64 /* SkipTypeBaseClass */ | 8 /* SkipInstanceVariables */);
|
3512
3538
|
if (callMethod) {
|
3513
3539
|
return;
|
3514
3540
|
}
|
@@ -4097,10 +4123,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4097
4123
|
const decls = overrideSymbol.getDeclarations();
|
4098
4124
|
if (decls.length > 0) {
|
4099
4125
|
const lastDecl = decls[decls.length - 1];
|
4126
|
+
const primaryDecl = decls[0];
|
4100
4127
|
// Verify that the override type is assignable to (same or narrower than)
|
4101
4128
|
// the declared type of the base symbol.
|
4102
|
-
const
|
4103
|
-
|
4129
|
+
const isInvariant = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* Variable */ && !primaryDecl.isFinal;
|
4130
|
+
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4131
|
+
if (!this._evaluator.assignType(baseType, overrideType, diagAddendum,
|
4132
|
+
/* destTypeVarContext */ undefined,
|
4133
|
+
/* srcTypeVarContext */ undefined, isInvariant ? 1 /* EnforceInvariance */ : 0 /* Default */)) {
|
4134
|
+
if (isInvariant) {
|
4135
|
+
diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4136
|
+
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideIsInvariant());
|
4137
|
+
diagAddendum.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.overrideInvariantMismatch().format({
|
4138
|
+
overrideType: this._evaluator.printType(overrideType),
|
4139
|
+
baseType: this._evaluator.printType(baseType),
|
4140
|
+
}));
|
4141
|
+
}
|
4104
4142
|
const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleVariableOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.Localizer.Diagnostic.symbolOverridden().format({
|
4105
4143
|
name: memberName,
|
4106
4144
|
className: baseClassAndSymbol.classType.details.name,
|