@@ -1453,6 +1453,19 @@ def visit_call(self, node: nodes.Call) -> None:
1453
1453
"""Check that called functions/methods are inferred to callable objects,
1454
1454
and that passed arguments match the parameters in the inferred function.
1455
1455
"""
1456
+
1457
+ is_super = False
1458
+ if (
1459
+ isinstance (node .func , nodes .Attribute )
1460
+ and node .func .attrname == "__init__"
1461
+ and isinstance (node .func .expr , nodes .Call )
1462
+ and isinstance (node .func .expr .func , nodes .Name )
1463
+ and node .func .expr .func .name == "super"
1464
+ ):
1465
+ inferred = safe_infer (node .func .expr )
1466
+ if isinstance (inferred , astroid .objects .Super ):
1467
+ is_super = True
1468
+
1456
1469
called = safe_infer (node .func , compare_constructors = True )
1457
1470
1458
1471
self ._check_not_callable (node , called )
@@ -1483,13 +1496,19 @@ def _call_site_has_args(cs: arguments.CallSite) -> bool:
1483
1496
if called .name == "isinstance" :
1484
1497
# Verify whether second argument of isinstance is a valid type
1485
1498
self ._check_isinstance_args (node , callable_name )
1486
- # Built-in functions have no argument information.
1487
- # Check built-in __init__ ... a user-defined __init__ function
1488
- # is handled elsewhere.
1489
- if "BoundMethod __init__ of builtins.object" in str (called ):
1490
- if _call_site_has_args (call_site ):
1499
+ # Built-in functions have no argument information, but we know
1500
+ # super() only takes self.
1501
+ if is_super and utils .is_builtin_object (called ):
1502
+ if (
1503
+ (call_site := astroid .arguments .CallSite .from_call (node ))
1504
+ and call_site .positional_arguments
1505
+ and (first_arg := call_site .positional_arguments [0 ])
1506
+ and not (isinstance (first_arg , nodes .Name ) and first_arg .name == "self" )
1507
+ ):
1491
1508
self .add_message (
1492
- "too-many-function-args" , node = node , args = ("__init__" ,)
1509
+ "too-many-function-args" ,
1510
+ node = node ,
1511
+ args = (callable_name ,),
1493
1512
)
1494
1513
return
1495
1514
0 commit comments