mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
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:
parent
022b30a1f8
commit
6d79c5cada
@ -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) }),
|
||||
|
11
packages/pyright-internal/src/tests/samples/super13.py
Normal file
11
packages/pyright-internal/src/tests/samples/super13.py
Normal 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)
|
@ -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());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user