File tree Expand file tree Collapse file tree 3 files changed +8
-6
lines changed
packages/pyright-internal/src/analyzer Expand file tree Collapse file tree 3 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ export function assignTypeToTypeVar(
201
201
// If the source and dest are both instantiables (type[T]), then
202
202
// we need to convert to an instance (T) for the
203
203
if ( TypeBase . isInstantiable ( srcType ) ) {
204
- constrainedType = convertToInstance ( srcType ) ;
204
+ constrainedType = convertToInstance ( srcType , /* includeSubclasses */ false ) ;
205
205
}
206
206
}
207
207
} else {
@@ -383,7 +383,7 @@ export function assignTypeToTypeVar(
383
383
384
384
if ( TypeBase . isInstantiable ( destType ) ) {
385
385
if ( isEffectivelyInstantiable ( adjSrcType ) ) {
386
- adjSrcType = convertToInstance ( adjSrcType ) ;
386
+ adjSrcType = convertToInstance ( adjSrcType , /* includeSubclasses */ false ) ;
387
387
} else {
388
388
diag ?. addMessage (
389
389
Localizer . DiagnosticAddendum . typeAssignmentMismatch ( ) . format ( {
Original file line number Diff line number Diff line change @@ -1668,7 +1668,7 @@ export function isEffectivelyInstantiable(type: Type): boolean {
1668
1668
return false ;
1669
1669
}
1670
1670
1671
- export function convertToInstance ( type : Type ) : Type {
1671
+ export function convertToInstance ( type : Type , includeSubclasses = true ) : Type {
1672
1672
let result = mapSubtypes ( type , ( subtype ) => {
1673
1673
switch ( subtype . category ) {
1674
1674
case TypeCategory . Class : {
@@ -1681,7 +1681,7 @@ export function convertToInstance(type: Type): Type {
1681
1681
}
1682
1682
}
1683
1683
1684
- return ClassType . cloneAsInstance ( subtype ) ;
1684
+ return ClassType . cloneAsInstance ( subtype , includeSubclasses ) ;
1685
1685
}
1686
1686
1687
1687
case TypeCategory . None : {
Original file line number Diff line number Diff line change @@ -603,14 +603,16 @@ export namespace ClassType {
603
603
return newClass ;
604
604
}
605
605
606
- export function cloneAsInstance ( type : ClassType ) : ClassType {
606
+ export function cloneAsInstance ( type : ClassType , includeSubclasses = true ) : ClassType {
607
607
if ( TypeBase . isInstance ( type ) ) {
608
608
return type ;
609
609
}
610
610
611
611
const newInstance = TypeBase . cloneTypeAsInstance ( type ) ;
612
612
newInstance . flags &= ~ TypeFlags . SpecialForm ;
613
- newInstance . includeSubclasses = true ;
613
+ if ( includeSubclasses ) {
614
+ newInstance . includeSubclasses = true ;
615
+ }
614
616
return newInstance ;
615
617
}
616
618
You can’t perform that action at this time.
0 commit comments