MCPcopy
hub / github.com/lutzroeder/netron / target

Method target

source/python.js:22372–22414  ·  view source on GitHub ↗
(expr, context)

Source from the content-addressed store, hash-verified

22370 }
22371
22372 target(expr, context) {
22373 const ast = this.ast;
22374 let current = expr;
22375 let path = [];
22376 for (;;) {
22377 if (current instanceof ast.Attribute) {
22378 path.push(current.attr);
22379 current = current.value;
22380 } else if (current instanceof ast.Name && current.id !== 'self' && current.id !== 'CONSTANTS') {
22381 path.push(current.id);
22382 break;
22383 } else {
22384 path = null;
22385 break;
22386 }
22387 }
22388 if (path) {
22389 let target = null;
22390 for (let i = path.length - 1; i >= 0; i--) {
22391 const name = path[i];
22392 if (target) {
22393 target = target.__getattr__ ? target.__getattr__(name) : target[name];
22394 } else {
22395 target = context.get(name);
22396 }
22397 if (!target) {
22398 break;
22399 }
22400 }
22401 if (!target) {
22402 path.reverse();
22403 const name = path.join('.');
22404 const file = `${path.join('/')}.py`;
22405 if (this._sources.has(file)) {
22406 target = this.import(name);
22407 } else {
22408 target = this.resolve(name);
22409 }
22410 }
22411 return target;
22412 }
22413 return this.expression(expr, context);
22414 }
22415
22416 add(name, source) {
22417 this._sources.set(name, source);

Callers 2

callMethod · 0.45
expressionMethod · 0.45

Calls 7

__getattr__Method · 0.80
expressionMethod · 0.80
pushMethod · 0.45
getMethod · 0.45
hasMethod · 0.45
importMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected