Fixed #162: Allow generic type (e.g. Type[T]) to be used as the annotation for a callable parameter or variable.

This commit is contained in:
Eric Traut 2019-07-05 09:15:45 -06:00
parent 932ee11b96
commit 21055c6b01

View File

@ -864,7 +864,14 @@ export class ExpressionEvaluator {
const typeArgs = objectClass.getTypeArguments();
if (typeArgs && typeArgs.length > 0) {
const firstTypeArg = typeArgs[0];
let firstTypeArg = typeArgs[0];
// If the type arg is a type var itself, specialize it in
// case it's bound or constrained.
if (firstTypeArg instanceof TypeVarType) {
firstTypeArg = TypeUtils.specializeTypeVarType(firstTypeArg);
}
if (firstTypeArg instanceof ObjectType) {
return firstTypeArg.getClassType();
}
@ -1316,7 +1323,9 @@ export class ExpressionEvaluator {
// Handle the "Type" object specially.
const classFromTypeObject = this._getClassFromPotentialTypeObject(callType);
if (classFromTypeObject) {
if (classFromTypeObject instanceof ClassType) {
if (classFromTypeObject.isAny()) {
type = classFromTypeObject;
} else if (classFromTypeObject instanceof ClassType) {
type = this._validateConstructorArguments(errorNode,
argList, classFromTypeObject);
}