@@ -1053,7 +1053,10 @@ def get_kind(arg_name: str) -> nodes.ArgKind:
1053
1053
1054
1054
1055
1055
def _verify_signature (
1056
- stub : Signature [nodes .Argument ], runtime : Signature [inspect .Parameter ], function_name : str
1056
+ stub : Signature [nodes .Argument ],
1057
+ runtime : Signature [inspect .Parameter ],
1058
+ function_name : str ,
1059
+ warn_runtime_is_object_init : bool = False ,
1057
1060
) -> Iterator [str ]:
1058
1061
# Check positional arguments match up
1059
1062
for stub_arg , runtime_arg in zip (stub .pos , runtime .pos ):
@@ -1098,6 +1101,8 @@ def _verify_signature(
1098
1101
msg = f'runtime does not have parameter "{ stub_arg .variable .name } "'
1099
1102
if runtime .varkw is not None :
1100
1103
msg += ". Maybe you forgot to make it keyword-only in the stub?"
1104
+ elif warn_runtime_is_object_init :
1105
+ msg += ". You may need to write stubs for __new__ instead of __init__."
1101
1106
yield msg
1102
1107
else :
1103
1108
yield f'stub parameter "{ stub_arg .variable .name } " is not keyword-only'
@@ -1137,7 +1142,11 @@ def _verify_signature(
1137
1142
if arg not in {runtime_arg .name for runtime_arg in runtime .pos [len (stub .pos ) :]}:
1138
1143
yield f'runtime parameter "{ arg } " is not keyword-only'
1139
1144
else :
1140
- yield f'runtime does not have parameter "{ arg } "'
1145
+ msg = f'runtime does not have parameter "{ arg } "'
1146
+ if warn_runtime_is_object_init :
1147
+ msg += ". You may need to write stubs for __new__ instead of __init__."
1148
+ yield msg
1149
+
1141
1150
for arg in sorted (set (runtime .kwonly ) - set (stub .kwonly )):
1142
1151
if arg in {stub_arg .variable .name for stub_arg in stub .pos }:
1143
1152
# Don't report this if we've reported it before
@@ -1223,7 +1232,12 @@ def verify_funcitem(
1223
1232
if not signature :
1224
1233
return
1225
1234
1226
- for message in _verify_signature (stub_sig , runtime_sig , function_name = stub .name ):
1235
+ for message in _verify_signature (
1236
+ stub_sig ,
1237
+ runtime_sig ,
1238
+ function_name = stub .name ,
1239
+ warn_runtime_is_object_init = runtime is object .__init__ ,
1240
+ ):
1227
1241
yield Error (
1228
1242
object_path ,
1229
1243
"is inconsistent, " + message ,
@@ -1333,7 +1347,12 @@ def verify_overloadedfuncdef(
1333
1347
stub_sig = Signature .from_overloadedfuncdef (stub )
1334
1348
runtime_sig = Signature .from_inspect_signature (signature )
1335
1349
1336
- for message in _verify_signature (stub_sig , runtime_sig , function_name = stub .name ):
1350
+ for message in _verify_signature (
1351
+ stub_sig ,
1352
+ runtime_sig ,
1353
+ function_name = stub .name ,
1354
+ warn_runtime_is_object_init = runtime is object .__init__ ,
1355
+ ):
1337
1356
# TODO: This is a little hacky, but the addition here is super useful
1338
1357
if "has a default value of type" in message :
1339
1358
message += (
0 commit comments