10000 Fixed a bug that resulted in incorrect `isinstance` type narrowing wh… · nejch/scip-python@8ae021c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ae021c

Browse files
committed
Fixed a bug that resulted in incorrect isinstance type narrowing when one or more of the filter classes was decorated with a class decorator.
1 parent cdb3516 commit 8ae021c

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

packages/pyright-internal/src/analyzer/constraintSolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export function assignTypeToTypeVar(
201201
// If the source and dest are both instantiables (type[T]), then
202202
// we need to convert to an instance (T) for the
203203
if (TypeBase.isInstantiable(srcType)) {
204-
constrainedType = convertToInstance(srcType);
204+
constrainedType = convertToInstance(srcType, /* includeSubclasses */ false);
205205
}
206206
}
207207
} else {
@@ -383,7 +383,7 @@ export function assignTypeToTypeVar(
383383

384384
if (TypeBase.isInstantiable(destType)) {
385385
if (isEffectivelyInstantiable(adjSrcType)) {
386-
adjSrcType = convertToInstance(adjSrcType);
386+
adjSrcType = convertToInstance(adjSrcType, /* includeSubclasses */ false);
387387
} else {
388388
diag?.addMessage(
389389
Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({

packages/pyright-internal/src/analyzer/typeUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ export function isEffectivelyInstantiable(type: Type): boolean {
16681668
return false;
16691669
}
16701670

1671-
export function convertToInstance(type: Type): Type {
1671+
export function convertToInstance(type: Type, includeSubclasses = true): Type {
16721672
let result = mapSubtypes(type, (subtype) => {
16731673
switch (subtype.category) {
16741674
case TypeCategory.Class: {
@@ -1681,7 +1681,7 @@ export function convertToInstance(type: Type): Type {
16811681
}
16821682
}
16831683

1684-
return ClassType.cloneAsInstance(subtype);
1684+
return ClassType.cloneAsInstance(subtype, includeSubclasses);
16851685
}
16861686

16871687
case TypeCategory.None: {

packages/pyright-internal/src/analyzer/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,16 @@ export namespace ClassType {
603603
return newClass;
604604
}
605605

606-
export function cloneAsInstance(type: ClassType): ClassType {
606+
export function cloneAsInstance(type: ClassType, includeSubclasses = true): ClassType {
607607
if (TypeBase.isInstance(type)) {
608608
return type;
609609
}
610610

611611
const newInstance = TypeBase.cloneTypeAsInstance(type);
612612
newInstance.flags &= ~TypeFlags.SpecialForm;
613-
newInstance.includeSubclasses = true;
613+
if (includeSubclasses) {
614+
newInstance.includeSubclasses = true;
615+
}
614616
return newInstance;
615617
}
616618

0 commit comments

Comments
 (0)
0