MCPcopy Index your code
hub / github.com/RustPython/RustPython / warn

Function warn

Lib/_py_warnings.py:443–495  ·  view source on GitHub ↗

Issue a warning, or maybe ignore it or raise an exception.

(message, category=None, stacklevel=1, source=None,
         *, skip_file_prefixes=())

Source from the content-addressed store, hash-verified

441
442# Code typically replaced by _warnings
443def warn(message, category=None, stacklevel=1, source=None,
444 *, skip_file_prefixes=()):
445 """Issue a warning, or maybe ignore it or raise an exception."""
446 # Check if message is already a Warning object
447 if isinstance(message, Warning):
448 category = message.__class__
449 # Check category argument
450 if category is None:
451 category = UserWarning
452 if not (isinstance(category, type) and issubclass(category, Warning)):
453 raise TypeError("category must be a Warning subclass, "
454 "not '{:s}'".format(type(category).__name__))
455 if not isinstance(skip_file_prefixes, tuple):
456 # The C version demands a tuple for implementation performance.
457 raise TypeError('skip_file_prefixes must be a tuple of strs.')
458 if skip_file_prefixes:
459 stacklevel = max(2, stacklevel)
460 # Get context information
461 try:
462 if stacklevel <= 1 or _is_internal_frame(sys._getframe(1)):
463 # If frame is too small to care or if the warning originated in
464 # internal code, then do not try to hide any frames.
465 frame = sys._getframe(stacklevel)
466 else:
467 frame = sys._getframe(1)
468 # Look for one frame less since the above line starts us off.
469 for x in range(stacklevel-1):
470 frame = _next_external_frame(frame, skip_file_prefixes)
471 if frame is None:
472 raise ValueError
473 except ValueError:
474 globals = sys.__dict__
475 filename = "<sys>"
476 lineno = 0
477 else:
478 globals = frame.f_globals
479 filename = frame.f_code.co_filename
480 lineno = frame.f_lineno
481 if '__name__' in globals:
482 module = globals['__name__']
483 else:
484 module = "<string>"
485 registry = globals.setdefault("__warningregistry__", {})
486 _wm.warn_explicit(
487 message,
488 category,
489 filename,
490 lineno,
491 module,
492 registry,
493 globals,
494 source=source,
495 )
496
497
498def warn_explicit(message, category, filename, lineno,

Callers 15

_get_module_detailsFunction · 0.90
_writeMethod · 0.90
adapt_dateFunction · 0.90
adapt_datetimeFunction · 0.90
convert_dateFunction · 0.90
convert_timestampFunction · 0.90
__serverMethod · 0.90
__lineMethod · 0.90
__stateMethod · 0.90
__greetingMethod · 0.90
__mailfromMethod · 0.90

Calls 7

isinstanceFunction · 0.85
issubclassFunction · 0.85
maxFunction · 0.85
_next_external_frameFunction · 0.85
_is_internal_frameFunction · 0.70
formatMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected