(
stub: nodes.FuncItem, runtime: MaybeMissing[Any], object_path: list[str]
)
| 1234 | |
| 1235 | @verify.register(nodes.FuncItem) |
| 1236 | def verify_funcitem( |
| 1237 | stub: nodes.FuncItem, runtime: MaybeMissing[Any], object_path: list[str] |
| 1238 | ) -> Iterator[Error]: |
| 1239 | if isinstance(runtime, Missing): |
| 1240 | yield Error(object_path, "is not present at runtime", stub, runtime) |
| 1241 | return |
| 1242 | |
| 1243 | if not is_probably_a_function(runtime): |
| 1244 | yield Error(object_path, "is not a function", stub, runtime) |
| 1245 | if not callable(runtime): |
| 1246 | return |
| 1247 | |
| 1248 | # Look the object up statically, to avoid binding by the descriptor protocol |
| 1249 | static_runtime = _static_lookup_runtime(object_path) |
| 1250 | |
| 1251 | if isinstance(stub, nodes.FuncDef): |
| 1252 | for error_text in _verify_abstract_status(stub, runtime): |
| 1253 | yield Error(object_path, error_text, stub, runtime) |
| 1254 | for error_text in _verify_final_method(stub, runtime, static_runtime): |
| 1255 | yield Error(object_path, error_text, stub, runtime) |
| 1256 | |
| 1257 | for message in _verify_static_class_methods(stub, runtime, static_runtime, object_path): |
| 1258 | yield Error(object_path, "is inconsistent, " + message, stub, runtime) |
| 1259 | |
| 1260 | signature = safe_inspect_signature(runtime) |
| 1261 | runtime_is_coroutine = inspect.iscoroutinefunction(runtime) |
| 1262 | |
| 1263 | if signature: |
| 1264 | stub_sig = Signature.from_funcitem(stub) |
| 1265 | runtime_sig = Signature.from_inspect_signature(signature) |
| 1266 | runtime_sig_desc = describe_runtime_callable(signature, is_async=runtime_is_coroutine) |
| 1267 | stub_desc = str(stub_sig) |
| 1268 | else: |
| 1269 | runtime_sig_desc, stub_desc = None, None |
| 1270 | |
| 1271 | # Don't raise an error if the stub is a coroutine, but the runtime isn't. |
| 1272 | # That results in false positives. |
| 1273 | # See https://github.com/python/typeshed/issues/7344 |
| 1274 | if runtime_is_coroutine and not stub.is_coroutine: |
| 1275 | yield Error( |
| 1276 | object_path, |
| 1277 | 'is an "async def" function at runtime, but not in the stub', |
| 1278 | stub, |
| 1279 | runtime, |
| 1280 | stub_desc=stub_desc, |
| 1281 | runtime_desc=runtime_sig_desc, |
| 1282 | ) |
| 1283 | |
| 1284 | if not signature: |
| 1285 | return |
| 1286 | |
| 1287 | for message in _verify_signature( |
| 1288 | stub_sig, |
| 1289 | runtime_sig, |
| 1290 | function_name=stub.name, |
| 1291 | warn_runtime_is_object_init=runtime is object.__init__, |
| 1292 | ): |
| 1293 | yield Error( |
nothing calls this directly
no test coverage detected
searching dependent graphs…