(
category: Option<PyTypeRef>,
message: PyObjectRef,
filename: PyStrRef,
lineno: usize,
module: Option<PyObjectRef>,
registry: PyObjectRef,
source_line: Option<PyObjectRef>
| 333 | /// Core warning logic matching `warn_explicit()` in `_warnings.c`. |
| 334 | #[allow(clippy::too_many_arguments)] |
| 335 | pub(crate) fn warn_explicit( |
| 336 | category: Option<PyTypeRef>, |
| 337 | message: PyObjectRef, |
| 338 | filename: PyStrRef, |
| 339 | lineno: usize, |
| 340 | module: Option<PyObjectRef>, |
| 341 | registry: PyObjectRef, |
| 342 | source_line: Option<PyObjectRef>, |
| 343 | source: Option<PyObjectRef>, |
| 344 | vm: &VirtualMachine, |
| 345 | ) -> PyResult<()> { |
| 346 | // Normalize module. None → silent return (late-shutdown safety). |
| 347 | let module = module.unwrap_or_else(|| normalize_module(&filename, vm)); |
| 348 | if vm.is_none(&module) { |
| 349 | return Ok(()); |
| 350 | } |
| 351 | |
| 352 | // Normalize message. |
| 353 | let is_warning = message.fast_isinstance(vm.ctx.exceptions.warning); |
| 354 | let (text, category, message) = if is_warning { |
| 355 | let text = message.str(vm)?; |
| 356 | let cat = message.class().to_owned(); |
| 357 | (text, cat, message) |
| 358 | } else { |
| 359 | // For non-Warning messages, convert to string via str() |
| 360 | let text = message.str(vm)?; |
| 361 | let cat = category.unwrap_or_else(|| vm.ctx.exceptions.user_warning.to_owned()); |
| 362 | let instance = cat.as_object().call((text.clone(),), vm)?; |
| 363 | (text, cat, instance) |
| 364 | }; |
| 365 | |
| 366 | let lineno_obj: PyObjectRef = vm.ctx.new_int(lineno).into(); |
| 367 | |
| 368 | // key = (text, category, lineno) |
| 369 | let key: PyObjectRef = PyTuple::new_ref( |
| 370 | vec![ |
| 371 | text.clone().into(), |
| 372 | category.as_object().to_owned(), |
| 373 | lineno_obj.clone(), |
| 374 | ], |
| 375 | &vm.ctx, |
| 376 | ) |
| 377 | .into(); |
| 378 | |
| 379 | // Check if already warned |
| 380 | if !vm.is_none(®istry) && already_warned(®istry, key.clone(), false, vm)? { |
| 381 | return Ok(()); |
| 382 | } |
| 383 | |
| 384 | // Get filter action |
| 385 | let action = get_filter( |
| 386 | category.as_object().to_owned(), |
| 387 | text.clone().into(), |
| 388 | lineno, |
| 389 | module, |
| 390 | vm, |
| 391 | )?; |
| 392 | let action_str = PyStrRef::try_from_object(vm, action) |
no test coverage detected