mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Added minimal handling of ClassVar.
Fixed bug in type analyzer related to property analysis.
This commit is contained in:
parent
c042723aa6
commit
84c187a47b
@ -501,11 +501,14 @@ export class ExpressionEvaluator {
|
||||
} else if (baseType instanceof ObjectType) {
|
||||
// TODO - need to implement
|
||||
type = UnknownType.create();
|
||||
} else if (baseType instanceof TupleType) {
|
||||
// TODO - need to implement
|
||||
type = UnknownType.create();
|
||||
}
|
||||
|
||||
if (!type) {
|
||||
this._addError(
|
||||
`'Unsupported expression type: indexed (${ baseType.asString() })`,
|
||||
`'Unsupported expression type: indexed ${ baseType.asString() }`,
|
||||
node.baseExpression);
|
||||
|
||||
type = UnknownType.create();
|
||||
@ -1325,10 +1328,14 @@ export class ExpressionEvaluator {
|
||||
} else {
|
||||
this._addError(`Expected parameter type list or '...'`, typeArgs[0].node);
|
||||
}
|
||||
} else {
|
||||
TypeUtils.addDefaultFunctionParameters(functionType);
|
||||
}
|
||||
|
||||
if (typeArgs.length > 1) {
|
||||
functionType.setDeclaredReturnType(typeArgs[1].type);
|
||||
} else {
|
||||
functionType.setDeclaredReturnType(AnyType.create());
|
||||
}
|
||||
|
||||
if (typeArgs.length > 2) {
|
||||
@ -1339,7 +1346,7 @@ export class ExpressionEvaluator {
|
||||
}
|
||||
|
||||
// Creates an Optional type annotation.
|
||||
private _createOptional(errorNode: ExpressionNode, typeArgs: TypeResult[]): Type {
|
||||
private _createOptionalType(errorNode: ExpressionNode, typeArgs: TypeResult[]): Type {
|
||||
if (typeArgs.length !== 1) {
|
||||
this._addError(`Expected one type parameter after Optional`, errorNode);
|
||||
return UnknownType.create();
|
||||
@ -1348,6 +1355,15 @@ export class ExpressionEvaluator {
|
||||
return TypeUtils.combineTypes(typeArgs[0].type, NoneType.create());
|
||||
}
|
||||
|
||||
private _createClassVarType(typeArgs: TypeResult[], flags: EvaluatorFlags): Type {
|
||||
if (typeArgs.length > 1) {
|
||||
this._addError(`Expected only one type parameter after ClassVar`, typeArgs[1].node);
|
||||
}
|
||||
|
||||
let type = (typeArgs.length === 0) ? AnyType.create() : typeArgs[0].type;
|
||||
return this._convertClassToObject(type, flags);
|
||||
}
|
||||
|
||||
// Creates a Type type annotation.
|
||||
private _createTypeType(errorNode: ExpressionNode, typeArgs: TypeResult[]): Type {
|
||||
if (typeArgs.length !== 1) {
|
||||
@ -1508,14 +1524,19 @@ export class ExpressionEvaluator {
|
||||
}
|
||||
|
||||
case 'Optional': {
|
||||
return this._createOptional(errorNode, typeArgs);
|
||||
return this._createOptionalType(errorNode, typeArgs);
|
||||
}
|
||||
|
||||
case 'Type': {
|
||||
return this._createTypeType(errorNode, typeArgs);
|
||||
}
|
||||
|
||||
case 'ClassVar':
|
||||
case 'ClassVar': {
|
||||
// TODO - need to handle class vars. For now, we treat them
|
||||
// like any other type.
|
||||
return this._createClassVarType(typeArgs, flags);
|
||||
}
|
||||
|
||||
case 'Deque':
|
||||
case 'List':
|
||||
case 'FrozenSet':
|
||||
|
@ -250,9 +250,9 @@ export abstract class SemanticAnalyzer extends ParseTreeWalker {
|
||||
} else {
|
||||
// Determine if the function is a property getter or setter.
|
||||
if (ParseTreeUtils.isFunctionInClass(node)) {
|
||||
functionType.clearHasCustomDecoratorsFlag();
|
||||
let propertyType = evaluator.getPropertyType(node, functionType);
|
||||
if (propertyType) {
|
||||
functionType.clearHasCustomDecoratorsFlag();
|
||||
decoratedType = propertyType;
|
||||
|
||||
// Allow setters or deleters to replace the getter.
|
||||
|
@ -87,16 +87,6 @@ export class TypeUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (srcType instanceof TypeVarType) {
|
||||
// TODO - remove this once we properly resolve generic types
|
||||
return true;
|
||||
}
|
||||
|
||||
if (destType instanceof TypeVarType) {
|
||||
// TODO - remove this once we properly resolve generic types
|
||||
return true;
|
||||
}
|
||||
|
||||
if (destType instanceof ObjectType) {
|
||||
const destClassType = destType.getClassType();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user