Fixed a bug that leads to a false positive error when first argument to super call is an instance of a metaclass. This addresses #7931.

This commit is contained in:
Eric Traut 2024-05-15 20:11:09 -07:00
parent 022b30a1f8
commit 6d79c5cada
3 changed files with 22 additions and 1 deletions

View File

@ -8378,7 +8378,11 @@ export function createTypeEvaluator(
targetClassType = getTypeOfExpression(node.arguments[0].valueExpression).type;
const concreteTargetClassType = makeTopLevelTypeVarsConcrete(targetClassType);
if (!isAnyOrUnknown(concreteTargetClassType) && !isInstantiableClass(concreteTargetClassType)) {
if (
!isAnyOrUnknown(concreteTargetClassType) &&
!isInstantiableClass(concreteTargetClassType) &&
!isMetaclassInstance(concreteTargetClassType)
) {
addDiagnostic(
DiagnosticRule.reportArgumentType,
LocMessage.superCallFirstArg().format({ type: printType(targetClassType) }),

View File

@ -0,0 +1,11 @@
# This sample tests the use of `super` outside of a method.
def func1(t: type) -> super:
return super(t, t)
class ClassA:
pass
func1(ClassA)

View File

@ -240,6 +240,12 @@ test('Super12', () => {
TestUtils.validateResults(analysisResults, 1);
});
test('Super13', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['super13.py']);
TestUtils.validateResults(analysisResults, 0);
});
test('MissingSuper1', () => {
const configOptions = new ConfigOptions(Uri.empty());