MCPcopy Index your code
hub / github.com/python/cpython / _showwarning

Function _showwarning

Lib/logging/__init__.py:2313–2331  ·  view source on GitHub ↗

Implementation of showwarnings which redirects to logging, which will first check to see if the file parameter is None. If a file is specified, it will delegate to the original warnings implementation of showwarning. Otherwise, it will call warnings.formatwarning and will log the re

(message, category, filename, lineno, file=None, line=None)

Source from the content-addressed store, hash-verified

2311_warnings_showwarning = None
2312
2313def _showwarning(message, category, filename, lineno, file=None, line=None):
2314 """
2315 Implementation of showwarnings which redirects to logging, which will first
2316 check to see if the file parameter is None. If a file is specified, it will
2317 delegate to the original warnings implementation of showwarning. Otherwise,
2318 it will call warnings.formatwarning and will log the resulting string to a
2319 warnings logger named "py.warnings" with level logging.WARNING.
2320 """
2321 if file is not None:
2322 if _warnings_showwarning is not None:
2323 _warnings_showwarning(message, category, filename, lineno, file, line)
2324 else:
2325 s = warnings.formatwarning(message, category, filename, lineno, line)
2326 logger = getLogger("py.warnings")
2327 if not logger.handlers:
2328 logger.addHandler(NullHandler())
2329 # bpo-46557: Log str(s) as msg instead of logger.warning("%s", s)
2330 # since some log aggregation tools group logs by the msg arg
2331 logger.warning(str(s))
2332
2333def captureWarnings(capture):
2334 """

Callers

nothing calls this directly

Calls 5

getLoggerFunction · 0.85
NullHandlerClass · 0.85
strFunction · 0.85
addHandlerMethod · 0.80
warningMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…