@zzzen/pyright-internal 1.2.0-dev.20240811 → 1.2.0-dev.20240818
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/analyzerFileInfo.js +1 -1
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/checker.js +4 -4
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +2 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/enums.js +1 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.js +3 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +136 -117
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/protocols.js +29 -20
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +2 -1
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +9 -9
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/tuples.js +3 -3
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +75 -71
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -1
- package/dist/analyzer/typeUtils.js +15 -4
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.js +3 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundThreadBase.js +0 -7
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/fullAccessHost.js +1 -1
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/pythonVersion.d.ts +17 -20
- package/dist/common/pythonVersion.js +81 -85
- package/dist/common/pythonVersion.js.map +1 -1
- package/dist/languageService/completionProvider.js +2 -2
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -4
- package/dist/localization/localize.js +2 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +0 -2
- package/dist/localization/package.nls.de.json +0 -2
- package/dist/localization/package.nls.en-us.json +2 -2
- package/dist/localization/package.nls.es.json +0 -2
- package/dist/localization/package.nls.fr.json +0 -2
- package/dist/localization/package.nls.it.json +0 -2
- package/dist/localization/package.nls.ja.json +0 -2
- package/dist/localization/package.nls.ko.json +0 -2
- package/dist/localization/package.nls.pl.json +0 -2
- package/dist/localization/package.nls.pt-br.json +0 -2
- package/dist/localization/package.nls.qps-ploc.json +0 -2
- package/dist/localization/package.nls.ru.json +0 -2
- package/dist/localization/package.nls.tr.json +0 -2
- package/dist/localization/package.nls.zh-cn.json +0 -2
- package/dist/localization/package.nls.zh-tw.json +0 -2
- package/dist/parser/parser.js +32 -23
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +2 -2
- package/package.json +1 -1
@@ -56,6 +56,7 @@ const analyzerFileInfo_1 = require("./analyzerFileInfo");
|
|
56
56
|
const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
|
57
57
|
const codeFlowEngine_1 = require("./codeFlowEngine");
|
58
58
|
const codeFlowTypes_1 = require("./codeFlowTypes");
|
59
|
+
const constraintSolution_1 = require("./constraintSolution");
|
59
60
|
const constraintSolver_1 = require("./constraintSolver");
|
60
61
|
const constraintTracker_1 = require("./constraintTracker");
|
61
62
|
const constructors_1 = require("./constructors");
|
@@ -3410,7 +3411,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3410
3411
|
}
|
3411
3412
|
else if ((0, types_1.isTypeVarTuple)(param) && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
3412
3413
|
defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
3413
|
-
/*
|
3414
|
+
/* isUnpacked */ true);
|
3414
3415
|
}
|
3415
3416
|
else {
|
3416
3417
|
defaultType = types_1.UnknownType.create();
|
@@ -3789,8 +3790,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3789
3790
|
if (usage.method === 'get') {
|
3790
3791
|
const getAttrSymbol = types_1.ModuleType.getField(baseType, '__getattr__');
|
3791
3792
|
if (getAttrSymbol) {
|
3792
|
-
const isModuleGetAttrSupported = fileInfo.executionEnvironment.pythonVersion
|
3793
|
-
getAttrSymbol.getDeclarations().some((decl) => decl.uri.hasExtension('.pyi'));
|
3793
|
+
const isModuleGetAttrSupported = pythonVersion_1.PythonVersion.isGreaterOrEqualTo(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_7) || getAttrSymbol.getDeclarations().some((decl) => decl.uri.hasExtension('.pyi'));
|
3794
3794
|
if (isModuleGetAttrSupported) {
|
3795
3795
|
const getAttrTypeResult = getEffectiveTypeOfSymbolForUsage(getAttrSymbol);
|
3796
3796
|
if ((0, types_1.isFunction)(getAttrTypeResult.type)) {
|
@@ -4550,7 +4550,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4550
4550
|
!baseTypeResult.type.priv.aliasName) {
|
4551
4551
|
const minPythonVersion = nonSubscriptableBuiltinTypes.get(baseTypeResult.type.shared.fullName);
|
4552
4552
|
if (minPythonVersion !== undefined &&
|
4553
|
-
fileInfo.executionEnvironment.pythonVersion
|
4553
|
+
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, minPythonVersion) &&
|
4554
4554
|
!fileInfo.isStubFile) {
|
4555
4555
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIndexIssue, localize_1.LocMessage.classNotRuntimeSubscriptable().format({
|
4556
4556
|
name: baseTypeResult.type.priv.aliasName || baseTypeResult.type.shared.name,
|
@@ -4687,7 +4687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4687
4687
|
}
|
4688
4688
|
});
|
4689
4689
|
}
|
4690
|
-
const tupleObject = makeTupleObject(variadicTypes, /*
|
4690
|
+
const tupleObject = makeTupleObject(variadicTypes, /* isUnpacked */ true);
|
4691
4691
|
typeArgs = [
|
4692
4692
|
...typeArgs.slice(0, variadicIndex),
|
4693
4693
|
{ node: typeArgs[variadicIndex].node, type: tupleObject },
|
@@ -4699,7 +4699,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4699
4699
|
// Add an empty tuple that maps to the TypeVarTuple type parameter.
|
4700
4700
|
typeArgs.push({
|
4701
4701
|
node: errorNode,
|
4702
|
-
type: makeTupleObject([], /*
|
4702
|
+
type: makeTupleObject([], /* isUnpacked */ true),
|
4703
4703
|
});
|
4704
4704
|
}
|
4705
4705
|
}
|
@@ -5148,9 +5148,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5148
5148
|
}
|
5149
5149
|
});
|
5150
5150
|
}
|
5151
|
-
function makeTupleObject(typeArgs,
|
5151
|
+
function makeTupleObject(typeArgs, isUnpacked = false) {
|
5152
5152
|
if (tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
5153
|
-
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClass, typeArgs, /* isTypeArgExplicit */ true,
|
5153
|
+
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClass, typeArgs, /* isTypeArgExplicit */ true, isUnpacked));
|
5154
5154
|
}
|
5155
5155
|
return types_1.UnknownType.create();
|
5156
5156
|
}
|
@@ -7196,7 +7196,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7196
7196
|
}
|
7197
7197
|
else {
|
7198
7198
|
positionalOnlyLimitIndex = varArgListParamIndex;
|
7199
|
-
positionalArgCount = varArgListParamIndex;
|
7199
|
+
positionalArgCount = Math.min(varArgListParamIndex, positionalArgCount);
|
7200
7200
|
positionParamLimitIndex = varArgListParamIndex;
|
7201
7201
|
}
|
7202
7202
|
}
|
@@ -7930,7 +7930,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7930
7930
|
specializedTuple = tupleTypeArgs[0].type;
|
7931
7931
|
}
|
7932
7932
|
else {
|
7933
|
-
specializedTuple = makeTupleObject(tupleTypeArgs, /*
|
7933
|
+
specializedTuple = makeTupleObject(tupleTypeArgs, /* isUnpacked */ true);
|
7934
7934
|
}
|
7935
7935
|
const combinedArg = {
|
7936
7936
|
paramCategory: 1 /* ParamCategory.ArgsList */,
|
@@ -8263,10 +8263,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8263
8263
|
}
|
8264
8264
|
// If the final return type is an unpacked tuple, turn it into a normal (unpacked) tuple.
|
8265
8265
|
if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
|
8266
|
-
specializedReturnType = types_1.ClassType.cloneForUnpacked(specializedReturnType, /*
|
8266
|
+
specializedReturnType = types_1.ClassType.cloneForUnpacked(specializedReturnType, /* isUnpacked */ false);
|
8267
8267
|
}
|
8268
8268
|
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
|
8269
|
-
specializedReturnType = adjustCallableReturnType(
|
8269
|
+
specializedReturnType = adjustCallableReturnType(errorNode, specializedReturnType, liveTypeVarScopes);
|
8270
8270
|
if (specializedInitSelfType) {
|
8271
8271
|
specializedInitSelfType = solveAndApplyConstraints(specializedInitSelfType, constraints);
|
8272
8272
|
}
|
@@ -8313,21 +8313,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8313
8313
|
// to allow these type vars to be solved. This won't work with overloads
|
8314
8314
|
// or unions of callables. It's intended for a specific use case. We may
|
8315
8315
|
// need to make this more sophisticated in the future.
|
8316
|
-
function adjustCallableReturnType(
|
8317
|
-
|
8318
|
-
if (!(0, types_1.isFunction)(returnType) || returnType.shared.name || !callableType.shared.typeVarScopeId) {
|
8316
|
+
function adjustCallableReturnType(callNode, returnType, liveTypeVarScopes) {
|
8317
|
+
if (!(0, types_1.isFunction)(returnType)) {
|
8319
8318
|
return returnType;
|
8320
8319
|
}
|
8321
8320
|
// What type variables are referenced in the callable return type? Do not include any live type variables.
|
8322
|
-
const
|
8321
|
+
const typeParams = (0, typeUtils_1.getTypeVarArgsRecursive)(returnType).filter((t) => !liveTypeVarScopes.some((scopeId) => t.priv.scopeId === scopeId));
|
8323
8322
|
// If there are no unsolved type variables, we're done. If there are
|
8324
|
-
// unsolved type variables,
|
8325
|
-
|
8326
|
-
if (newTypeParams.length === 0) {
|
8323
|
+
// unsolved type variables, rescope them to the callable.
|
8324
|
+
if (typeParams.length === 0) {
|
8327
8325
|
return returnType;
|
8328
8326
|
}
|
8329
|
-
|
8330
|
-
|
8327
|
+
inferReturnTypeIfNecessary(returnType);
|
8328
|
+
// Create a new scope ID based on the caller's position. This
|
8329
|
+
// will guarantee uniqueness. If another caller uses the same
|
8330
|
+
// call and arguments, the type vars will not conflict.
|
8331
|
+
const newScopeId = ParseTreeUtils.getScopeIdForNode(callNode);
|
8332
|
+
const solution = new constraintSolution_1.ConstraintSolution();
|
8333
|
+
const newTypeParams = typeParams.map((typeVar) => {
|
8334
|
+
const newTypeParam = types_1.TypeVarType.cloneForScopeId(typeVar, newScopeId, typeVar.priv.scopeName, 1 /* TypeVarScopeType.Function */);
|
8335
|
+
solution.setType(typeVar, newTypeParam);
|
8336
|
+
return newTypeParam;
|
8337
|
+
});
|
8338
|
+
return (0, typeUtils_1.applySolvedTypeVars)(types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, newScopeId,
|
8339
|
+
/* constructorTypeVarScopeId */ undefined, newTypeParams), solution);
|
8331
8340
|
}
|
8332
8341
|
// Tries to assign the call arguments to the function parameter
|
8333
8342
|
// list and reports any mismatches in types or counts. Returns the
|
@@ -8746,7 +8755,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8746
8755
|
typeVar.shared.isDefaultExplicit = true;
|
8747
8756
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8748
8757
|
if (!fileInfo.isStubFile &&
|
8749
|
-
fileInfo.executionEnvironment.pythonVersion
|
8758
|
+
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_13) &&
|
8750
8759
|
classType.shared.moduleName !== 'typing_extensions') {
|
8751
8760
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultIllegal(), defaultValueNode);
|
8752
8761
|
}
|
@@ -8850,7 +8859,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8850
8859
|
}
|
8851
8860
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8852
8861
|
if (!fileInfo.isStubFile &&
|
8853
|
-
fileInfo.executionEnvironment.pythonVersion
|
8862
|
+
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_13) &&
|
8854
8863
|
classType.shared.moduleName !== 'typing_extensions') {
|
8855
8864
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultIllegal(), expr);
|
8856
8865
|
}
|
@@ -8911,7 +8920,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8911
8920
|
}
|
8912
8921
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8913
8922
|
if (!fileInfo.isStubFile &&
|
8914
|
-
fileInfo.executionEnvironment.pythonVersion
|
8923
|
+
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_13) &&
|
8915
8924
|
classType.shared.moduleName !== 'typing_extensions') {
|
8916
8925
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultIllegal(), expr);
|
8917
8926
|
}
|
@@ -10614,10 +10623,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10614
10623
|
}
|
10615
10624
|
return type;
|
10616
10625
|
}
|
10617
|
-
// Creates a "TypeGuard" and "TypeIs" type.
|
10618
|
-
// isn't a generic type and therefore doesn't have a typeParam.
|
10619
|
-
// We'll abuse our internal types a bit by specializing it with
|
10620
|
-
// a type argument anyway.
|
10626
|
+
// Creates a "TypeGuard" and "TypeIs" type.
|
10621
10627
|
function createTypeGuardType(classType, errorNode, typeArgs, flags) {
|
10622
10628
|
// If no type arguments are provided, the resulting type
|
10623
10629
|
// depends on whether we're evaluating a type annotation or
|
@@ -11043,36 +11049,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11043
11049
|
})) {
|
11044
11050
|
typeArgType = types_1.UnknownType.create();
|
11045
11051
|
}
|
11046
|
-
|
11047
|
-
if ((0, types_1.isUnpackedClass)(typeArg.type) && typeArg.type.priv.tupleTypeArgs) {
|
11052
|
+
if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isUnpackedTypeVarTuple)(typeArgType)) {
|
11048
11053
|
// This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
|
11049
11054
|
if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
|
11050
|
-
|
11051
|
-
|
11052
|
-
|
11055
|
+
// If this is an unpacked TypeVar, note that it is in a union so we can
|
11056
|
+
// differentiate between Unpack[Vs] and Union[Unpack[Vs]].
|
11057
|
+
typeArgType = types_1.TypeVarType.cloneForUnpacked(typeArgType, /* isInUnion */ true);
|
11053
11058
|
allowSingleTypeArg = true;
|
11054
11059
|
}
|
11055
11060
|
else {
|
11056
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.
|
11057
|
-
|
11058
|
-
}
|
11059
|
-
}
|
11060
|
-
else {
|
11061
|
-
if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isUnpackedTypeVarTuple)(typeArgType)) {
|
11062
|
-
// This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
|
11063
|
-
if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
|
11064
|
-
// If this is an unpacked TypeVar, note that it is in a union so we can
|
11065
|
-
// differentiate between Unpack[Vs] and Union[Unpack[Vs]].
|
11066
|
-
typeArgType = types_1.TypeVarType.cloneForUnpacked(typeArgType, /* isInUnion */ true);
|
11067
|
-
allowSingleTypeArg = true;
|
11068
|
-
}
|
11069
|
-
else {
|
11070
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unionUnpackedTypeVarTuple(), errorNode);
|
11071
|
-
typeArgType = types_1.UnknownType.create();
|
11072
|
-
}
|
11061
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unionUnpackedTypeVarTuple(), errorNode);
|
11062
|
+
typeArgType = types_1.UnknownType.create();
|
11073
11063
|
}
|
11074
|
-
types.push(typeArgType);
|
11075
11064
|
}
|
11065
|
+
types.push(typeArgType);
|
11076
11066
|
}
|
11077
11067
|
// Validate that we received at least two type arguments. One type argument
|
11078
11068
|
// is allowed if it's an unpacked TypeVarTuple or tuple. None is also allowed
|
@@ -11229,7 +11219,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11229
11219
|
if (fileInfo.isTypingExtensionsStubFile) {
|
11230
11220
|
specialClassType.shared.flags |= 4096 /* ClassTypeFlags.TypingExtensionClass */;
|
11231
11221
|
}
|
11232
|
-
const baseClassName = aliasMapEntry.alias || 'object';
|
11222
|
+
const baseClassName = aliasMapEntry.implicitBaseClass || aliasMapEntry.alias || 'object';
|
11233
11223
|
let baseClass;
|
11234
11224
|
if (aliasMapEntry.module === 'builtins') {
|
11235
11225
|
baseClass = getBuiltInType(node, baseClassName);
|
@@ -11296,7 +11286,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11296
11286
|
['Concatenate', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11297
11287
|
[
|
11298
11288
|
'TypeGuard',
|
11299
|
-
{
|
11289
|
+
{
|
11290
|
+
alias: '',
|
11291
|
+
module: 'builtins',
|
11292
|
+
implicitBaseClass: 'bool',
|
11293
|
+
isSpecialForm: true,
|
11294
|
+
typeParamVariance: 3 /* Variance.Covariant */,
|
11295
|
+
},
|
11300
11296
|
],
|
11301
11297
|
['Unpack', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11302
11298
|
['Required', { alias: '', module: 'builtins', isSpecialForm: true }],
|
@@ -11306,7 +11302,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11306
11302
|
['Never', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11307
11303
|
['LiteralString', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11308
11304
|
['ReadOnly', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11309
|
-
[
|
11305
|
+
[
|
11306
|
+
'TypeIs',
|
11307
|
+
{
|
11308
|
+
alias: '',
|
11309
|
+
module: 'builtins',
|
11310
|
+
implicitBaseClass: 'bool',
|
11311
|
+
isSpecialForm: true,
|
11312
|
+
typeParamVariance: 2 /* Variance.Invariant */,
|
11313
|
+
},
|
11314
|
+
],
|
11310
11315
|
]);
|
11311
11316
|
const aliasMapEntry = specialTypes.get(assignedName);
|
11312
11317
|
if (aliasMapEntry) {
|
@@ -11743,7 +11748,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11743
11748
|
if (types_1.ClassType.isBuiltIn(argType, 'Protocol')) {
|
11744
11749
|
if (!fileInfo.isStubFile &&
|
11745
11750
|
!types_1.ClassType.isTypingExtensionClass(argType) &&
|
11746
|
-
fileInfo.executionEnvironment.pythonVersion
|
11751
|
+
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_7)) {
|
11747
11752
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.protocolIllegal(), arg.d.valueExpr);
|
11748
11753
|
}
|
11749
11754
|
classType.shared.flags |= 512 /* ClassTypeFlags.ProtocolClass */;
|
@@ -11753,7 +11758,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11753
11758
|
}
|
11754
11759
|
// If the class directly derives from NamedTuple (in Python 3.6 or
|
11755
11760
|
// newer), it's considered a (read-only) dataclass.
|
11756
|
-
if (fileInfo.executionEnvironment.pythonVersion
|
11761
|
+
if (pythonVersion_1.PythonVersion.isGreaterOrEqualTo(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_6)) {
|
11757
11762
|
if (types_1.ClassType.isBuiltIn(argType, 'NamedTuple')) {
|
11758
11763
|
isNamedTupleSubclass = true;
|
11759
11764
|
classType.shared.flags |= 524288 /* ClassTypeFlags.ReadOnlyInstanceVariables */;
|
@@ -13064,7 +13069,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13064
13069
|
return type;
|
13065
13070
|
}
|
13066
13071
|
if ((0, types_1.isUnpackedClass)(type)) {
|
13067
|
-
return types_1.ClassType.cloneForUnpacked(type, /*
|
13072
|
+
return types_1.ClassType.cloneForUnpacked(type, /* isUnpacked */ false);
|
13068
13073
|
}
|
13069
13074
|
return makeTupleObject([{ type, isUnbounded: !(0, types_1.isTypeVarTuple)(type) }]);
|
13070
13075
|
}
|
@@ -13531,7 +13536,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13531
13536
|
reportError = true;
|
13532
13537
|
// Handle PEP 562 support for module-level __getattr__ function,
|
13533
13538
|
// introduced in Python 3.7.
|
13534
|
-
if (fileInfo.executionEnvironment.pythonVersion
|
13539
|
+
if (pythonVersion_1.PythonVersion.isGreaterOrEqualTo(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_7) ||
|
13535
13540
|
fileInfo.isStubFile) {
|
13536
13541
|
const getAttrSymbol = importLookupInfo.symbolTable.get('__getattr__');
|
13537
13542
|
if (getAttrSymbol) {
|
@@ -14360,7 +14365,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14360
14365
|
}
|
14361
14366
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
14362
14367
|
if (fileInfo.isStubFile ||
|
14363
|
-
fileInfo.executionEnvironment.pythonVersion
|
14368
|
+
pythonVersion_1.PythonVersion.isGreaterOrEqualTo(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_9) ||
|
14364
14369
|
(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(errorNode)) ||
|
14365
14370
|
(flags & 4 /* EvalFlags.ForwardRefs */) !== 0) {
|
14366
14371
|
// Handle "type" specially, since it needs to act like "Type"
|
@@ -16374,13 +16379,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16374
16379
|
}
|
16375
16380
|
return true;
|
16376
16381
|
}
|
16377
|
-
// If the type is a bool created with a `TypeGuard` or `TypeIs`, it is
|
16378
|
-
// considered a subtype of `bool`.
|
16379
|
-
if ((0, types_1.isInstantiableClass)(srcType) && types_1.ClassType.isBuiltIn(srcType, ['TypeGuard', 'TypeIs'])) {
|
16380
|
-
if ((0, types_1.isInstantiableClass)(destType) && types_1.ClassType.isBuiltIn(destType, 'bool')) {
|
16381
|
-
return (flags & 1 /* AssignTypeFlags.Invariant */) === 0;
|
16382
|
-
}
|
16383
|
-
}
|
16384
16382
|
if ((flags & 1 /* AssignTypeFlags.Invariant */) === 0 || types_1.ClassType.isSameGenericClass(srcType, destType)) {
|
16385
16383
|
if (isDerivedFrom) {
|
16386
16384
|
(0, debug_1.assert)(inheritanceChain.length > 0);
|
@@ -16616,7 +16614,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16616
16614
|
const typeParam = destType.shared.typeParams[i];
|
16617
16615
|
const variance = types_1.TypeVarType.getVariance(typeParam);
|
16618
16616
|
if (curSrcType.priv.tupleTypeArgs) {
|
16619
|
-
typeArgType = (0, typeUtils_1.convertToInstance)(makeTupleObject(curSrcType.priv.tupleTypeArgs, /*
|
16617
|
+
typeArgType = (0, typeUtils_1.convertToInstance)(makeTupleObject(curSrcType.priv.tupleTypeArgs, /* isUnpacked */ true));
|
16620
16618
|
}
|
16621
16619
|
else {
|
16622
16620
|
typeArgType = i < srcTypeArgs.length ? srcTypeArgs[i] : types_1.UnknownType.create();
|
@@ -17733,7 +17731,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17733
17731
|
}
|
17734
17732
|
}
|
17735
17733
|
}
|
17736
|
-
|
17734
|
+
const callType = getBoundMagicMethod(objType, '__call__',
|
17735
|
+
/* selfType */ undefined,
|
17736
|
+
/* diag */ undefined, recursionCount);
|
17737
|
+
if (!callType) {
|
17738
|
+
return undefined;
|
17739
|
+
}
|
17740
|
+
return (0, typeUtils_1.makeFunctionTypeVarsBound)(callType);
|
17737
17741
|
}
|
17738
17742
|
function assignParam(destType, srcType, paramIndex, diag, constraints, flags, recursionCount) {
|
17739
17743
|
// Handle the special case where the dest type is a synthesized
|
@@ -17839,7 +17843,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17839
17843
|
}
|
17840
17844
|
});
|
17841
17845
|
if (srcTupleTypes.length !== 1 || !(0, types_1.isTypeVarTuple)(srcTupleTypes[0].type)) {
|
17842
|
-
const srcPositionalsType = makeTupleObject(srcTupleTypes, /*
|
17846
|
+
const srcPositionalsType = makeTupleObject(srcTupleTypes, /* isUnpacked */ true);
|
17843
17847
|
// Snip out the portion of the source positionals that map to the variadic
|
17844
17848
|
// dest parameter and replace it with a single parameter that is typed as a
|
17845
17849
|
// tuple containing the individual types of the replaced parameters.
|
@@ -18075,10 +18079,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18075
18079
|
let destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
|
18076
18080
|
let srcArgsType = srcParamDetails.params[srcParamDetails.argsIndex].type;
|
18077
18081
|
if (!(0, types_1.isUnpacked)(destArgsType)) {
|
18078
|
-
destArgsType = makeTupleObject([{ type: destArgsType, isUnbounded: true }], /*
|
18082
|
+
destArgsType = makeTupleObject([{ type: destArgsType, isUnbounded: true }], /* isUnpacked */ true);
|
18079
18083
|
}
|
18080
18084
|
if (!(0, types_1.isUnpacked)(srcArgsType)) {
|
18081
|
-
srcArgsType = makeTupleObject([{ type: srcArgsType, isUnbounded: true }], /*
|
18085
|
+
srcArgsType = makeTupleObject([{ type: srcArgsType, isUnbounded: true }], /* isUnpacked */ true);
|
18082
18086
|
}
|
18083
18087
|
if (!assignParam(destArgsType, srcArgsType, destParamDetails.params[destParamDetails.argsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, flags, recursionCount)) {
|
18084
18088
|
canAssign = false;
|