@@ -1453,6 +1453,19 @@ def visit_call(self, node: nodes.Call) -> None:
14531453 """Check that called functions/methods are inferred to callable objects,
14541454 and that passed arguments match the parameters in the inferred function.
14551455 """
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+
14561469 called = safe_infer (node .func , compare_constructors = True )
14571470
14581471 self ._check_not_callable (node , called )
@@ -1483,13 +1496,19 @@ def _call_site_has_args(cs: arguments.CallSite) -> bool:
14831496 if called .name == "isinstance" :
14841497 # Verify whether second argument of isinstance is a valid type
14851498 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+ ):
14911508 self .add_message (
1492- "too-many-function-args" , node = node , args = ("__init__" ,)
1509+ "too-many-function-args" ,
1510+ node = node ,
1511+ args = (callable_name ,),
14931512 )
14941513 return
14951514
0 commit comments