MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _main

Function _main

tools/python-3.11.9-amd64/Lib/inspect.py:3267–3322  ·  view source on GitHub ↗

Logic for inspecting an object given at command line

()

Source from the content-addressed store, hash-verified

3265
3266
3267def _main():
3268 """ Logic for inspecting an object given at command line """
3269 import argparse
3270 import importlib
3271
3272 parser = argparse.ArgumentParser()
3273 parser.add_argument(
3274 'object',
3275 help="The object to be analysed. "
3276 "It supports the 'module:qualname' syntax")
3277 parser.add_argument(
3278 '-d', '--details', action='store_true',
3279 help='Display info about the module rather than its source code')
3280
3281 args = parser.parse_args()
3282
3283 target = args.object
3284 mod_name, has_attrs, attrs = target.partition(":")
3285 try:
3286 obj = module = importlib.import_module(mod_name)
3287 except Exception as exc:
3288 msg = "Failed to import {} ({}: {})".format(mod_name,
3289 type(exc).__name__,
3290 exc)
3291 print(msg, file=sys.stderr)
3292 sys.exit(2)
3293
3294 if has_attrs:
3295 parts = attrs.split(".")
3296 obj = module
3297 for part in parts:
3298 obj = getattr(obj, part)
3299
3300 if module.__name__ in sys.builtin_module_names:
3301 print("Can't get info for builtin modules.", file=sys.stderr)
3302 sys.exit(1)
3303
3304 if args.details:
3305 print('Target: {}'.format(target))
3306 print('Origin: {}'.format(getsourcefile(module)))
3307 print('Cached: {}'.format(module.__cached__))
3308 if obj is module:
3309 print('Loader: {}'.format(repr(module.__loader__)))
3310 if hasattr(module, '__path__'):
3311 print('Submodule search path: {}'.format(module.__path__))
3312 else:
3313 try:
3314 __, lineno = findsource(obj)
3315 except Exception:
3316 pass
3317 else:
3318 print('Line: {}'.format(lineno))
3319
3320 print('\n')
3321 else:
3322 print(getsource(obj))
3323
3324

Callers 1

inspect.pyFile · 0.70

Calls 12

parse_argsMethod · 0.95
getsourcefileFunction · 0.85
findsourceFunction · 0.85
getsourceFunction · 0.85
partitionMethod · 0.80
import_moduleMethod · 0.80
typeClass · 0.50
printFunction · 0.50
add_argumentMethod · 0.45
formatMethod · 0.45
exitMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected