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

Method scan_code

Lib/modulefinder.py:402–449  ·  view source on GitHub ↗
(self, co, m)

Source from the content-addressed store, hash-verified

400 yield "relative_import", (level, fromlist, name)
401
402 def scan_code(self, co, m):
403 code = co.co_code
404 scanner = self.scan_opcodes
405 for what, args in scanner(co):
406 if what == "store":
407 name, = args
408 m.globalnames[name] = 1
409 elif what == "absolute_import":
410 fromlist, name = args
411 have_star = 0
412 if fromlist is not None:
413 if "*" in fromlist:
414 have_star = 1
415 fromlist = [f for f in fromlist if f != "*"]
416 self._safe_import_hook(name, m, fromlist, level=0)
417 if have_star:
418 # We've encountered an "import *". If it is a Python module,
419 # the code has already been parsed and we can suck out the
420 # global names.
421 mm = None
422 if m.__path__:
423 # At this point we don't know whether 'name' is a
424 # submodule of 'm' or a global module. Let's just try
425 # the full name first.
426 mm = self.modules.get(m.__name__ + "." + name)
427 if mm is None:
428 mm = self.modules.get(name)
429 if mm is not None:
430 m.globalnames.update(mm.globalnames)
431 m.starimports.update(mm.starimports)
432 if mm.__code__ is None:
433 m.starimports[name] = 1
434 else:
435 m.starimports[name] = 1
436 elif what == "relative_import":
437 level, fromlist, name = args
438 if name:
439 self._safe_import_hook(name, m, fromlist, level=level)
440 else:
441 parent = self.determine_parent(m, level=level)
442 self._safe_import_hook(parent.__name__, None, fromlist, level=0)
443 else:
444 # We don't expect anything else from the generator.
445 raise RuntimeError(what)
446
447 for c in co.co_consts:
448 if isinstance(c, type(co)):
449 self.scan_code(c, m)
450
451 def load_package(self, fqname, pathname):
452 self.msgin(2, "load_package", fqname, pathname)

Callers 1

load_moduleMethod · 0.95

Calls 5

_safe_import_hookMethod · 0.95
determine_parentMethod · 0.95
isinstanceFunction · 0.85
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected