Fixed a false positive error arising from the use of a binary expression for a base class in a class declaration statement. This addresses https://github.com/microsoft/pyright/pull/5326. (#5331)

Co-authored-by: Eric Traut <erictr@microsoft.com>
This commit is contained in:
Eric Traut 2023-06-18 00:17:53 -07:00 committed by GitHub
parent 2de35e3684
commit 02b7769198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -999,7 +999,15 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
}
case ParseNodeType.BinaryOperation: {
typeResult = getTypeOfBinaryOperation(evaluatorInterface, node, flags, inferenceContext);
let effectiveFlags = flags;
// If we're expecting an instantiable type and this isn't a union operator,
// don't require that the two operands are also instantiable types.
if (expectingInstantiable && node.operator !== OperatorType.BitwiseOr) {
effectiveFlags &= ~EvaluatorFlags.ExpectingInstantiableType;
}
typeResult = getTypeOfBinaryOperation(evaluatorInterface, node, effectiveFlags, inferenceContext);
break;
}

View File

@ -10,9 +10,16 @@ class A:
pass
def dynamic_subclass(cls: type[T_A]):
def dynamic_subclass1(cls: type[T_A]):
class SubClass(cls):
class SubInnerClass(cls.InnerA):
pass
return SubClass
def dynamic_subclass2(base: type[A] | None):
class SubClass(base or A):
...
return SubClass