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

Function _getcategory

Lib/_py_warnings.py:398–416  ·  view source on GitHub ↗
(category)

Source from the content-addressed store, hash-verified

396
397# Helper for _setoption()
398def _getcategory(category):
399 if not category:
400 return Warning
401 if '.' not in category:
402 import builtins as m
403 klass = category
404 else:
405 module, _, klass = category.rpartition('.')
406 try:
407 m = __import__(module, None, None, [klass])
408 except ImportError:
409 raise _wm._OptionError("invalid module name: %r" % (module,)) from None
410 try:
411 cat = getattr(m, klass)
412 except AttributeError:
413 raise _wm._OptionError("unknown warning category: %r" % (category,)) from None
414 if not issubclass(cat, Warning):
415 raise _wm._OptionError("invalid warning category: %r" % (category,))
416 return cat
417
418
419def _is_internal_filename(filename):

Callers

nothing calls this directly

Calls 4

getattrFunction · 0.85
issubclassFunction · 0.85
__import__Function · 0.50
rpartitionMethod · 0.45

Tested by

no test coverage detected