MCPcopy Index your code
hub / github.com/lutzroeder/netron / __import__

Method __import__

source/python.js:21881–21926  ·  view source on GitHub ↗
(name, globals, locals, fromlist, level)

Source from the content-addressed store, hash-verified

21879 }
21880
21881 __import__(name, globals, locals, fromlist, level) {
21882 let module = null;
21883 level = level || 0;
21884 if (level === 0) {
21885 module = this.import(name);
21886 } else {
21887 globals = globals || {};
21888 let current = globals.__package__;
21889 if (!current) {
21890 const spec = globals.__spec__;
21891 if (spec) {
21892 current = spec.parent;
21893 } else {
21894 const name = globals.__name__;
21895 const bits = name.split('.');
21896 bits.pop();
21897 current = bits.join('.');
21898 }
21899 }
21900 module = this.import(name, current, level);
21901 }
21902 if (!fromlist) {
21903 if (level === 0) {
21904 return this.import(name.split('.')[0]);
21905 } else if (name) {
21906 throw new python.Error(`Unsupported relative import '${name}'.`);
21907 // cut_off = len(name) - len(name.partition('.')[0])
21908 // return sys.modules[module.__name__[:len(module.__name__)-cut_off]]
21909 }
21910 } else if (module.__path__) {
21911 const handle_fromlist = (module, fromlist, recursive) => {
21912 for (const name of fromlist) {
21913 if (name === '*') {
21914 if (!recursive && module.__all__) {
21915 handle_fromlist(module, module.__all__, true);
21916 }
21917 } else if (!module[name]) {
21918 this.import(`${module.__name__}.${name}`);
21919 }
21920 }
21921 return module;
21922 };
21923 handle_fromlist(module, fromlist);
21924 }
21925 return module;
21926 }
21927
21928 module(name) {
21929 return this._modules.get(name);

Callers 15

exportMethod · 0.80
peekMethod · 0.80
constructorMethod · 0.80
registerMethod · 0.80
typeMethod · 0.80
openNumPyArrayPickleMethod · 0.80
constructorMethod · 0.80
find_classMethod · 0.80
readArchiveAndTensorsMethod · 0.80
constructorMethod · 0.80
statementMethod · 0.80
constructorMethod · 0.80

Calls 3

splitMethod · 0.80
importMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected