mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Simplified handling of TypeVars used in bound objects for constructor methods. (#8119)
This commit is contained in:
parent
0edcd2eecf
commit
0df185ebd4
@ -11411,19 +11411,6 @@ export function createTypeEvaluator(
|
||||
}
|
||||
}
|
||||
|
||||
if (type.boundTypeVarScopeId) {
|
||||
// If the function was bound to a class or object and was a constructor, a
|
||||
// static method or a class method, it's possible that some of that class's
|
||||
// type variables have not yet been solved. Add that class's TypeVar scope ID.
|
||||
if (type.preBoundFlags !== undefined && type.boundToType && requiresSpecialization(type.boundToType)) {
|
||||
if (
|
||||
type.preBoundFlags &
|
||||
(FunctionTypeFlags.StaticMethod | FunctionTypeFlags.ClassMethod | FunctionTypeFlags.StaticMethod)
|
||||
) {
|
||||
typeVarContext.addSolveForScope(type.boundTypeVarScopeId);
|
||||
}
|
||||
}
|
||||
|
||||
// The type annotation for the "self" parameter in an __init__ method to
|
||||
// can influence the type being constructed.
|
||||
if (
|
||||
@ -11446,7 +11433,6 @@ export function createTypeEvaluator(
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Special-case a few built-in calls that are often used for
|
||||
// casting or checking for unknown types.
|
||||
|
@ -1065,6 +1065,10 @@ export function getTypeVarScopeIds(type: Type): TypeVarScopeId[] | undefined {
|
||||
if (type.details.higherOrderTypeVarScopeIds) {
|
||||
scopeIds.push(...type.details.higherOrderTypeVarScopeIds);
|
||||
}
|
||||
|
||||
if (type.boundTypeVarScopeId) {
|
||||
scopeIds.push(type.boundTypeVarScopeId);
|
||||
}
|
||||
}
|
||||
|
||||
return scopeIds;
|
||||
|
@ -1537,7 +1537,8 @@ export interface FunctionType extends TypeBase {
|
||||
// The flags for the function prior to binding
|
||||
preBoundFlags?: FunctionTypeFlags;
|
||||
|
||||
// The type var scope for the class that the function was bound to
|
||||
// The type var scope for the class that the function was bound to.
|
||||
// This applies only to constructor methods.
|
||||
boundTypeVarScopeId?: TypeVarScopeId | undefined;
|
||||
|
||||
// If this function is part of an overloaded function, this
|
||||
@ -1657,7 +1658,10 @@ export namespace FunctionType {
|
||||
}
|
||||
|
||||
newFunction.inferredReturnType = type.inferredReturnType;
|
||||
|
||||
if (newFunction.preBoundFlags & FunctionTypeFlags.ConstructorMethod) {
|
||||
newFunction.boundTypeVarScopeId = boundTypeVarScopeId ?? type.boundTypeVarScopeId;
|
||||
}
|
||||
|
||||
return newFunction;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user