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

Method statement

source/python.js:22062–22194  ·  view source on GitHub ↗
(stmt, context)

Source from the content-addressed store, hash-verified

22060 }
22061
22062 statement(stmt, context) {
22063 const ast = this.ast;
22064 const builtins = this.builtins;
22065 if (stmt instanceof ast.Pass) {
22066 // pass
22067 } else if (stmt instanceof ast.Constant) {
22068 // pass
22069 } else if (stmt instanceof ast.Return) {
22070 return this.expression(stmt.value, context);
22071 } else if (stmt instanceof ast.FunctionDef) {
22072 const module = context.get('__name__');
22073 /* eslint-disable consistent-this */
22074 const self = this;
22075 /* eslint-enable consistent-this */
22076 const parent = context.get('__class__');
22077 const type = (parent === builtins.module) ? builtins.function : builtins.method;
22078 const func = {
22079 __class__: type,
22080 __globals__: context,
22081 __module__: module,
22082 __name__: stmt.name,
22083 __code__: stmt,
22084 __call__(args) {
22085 return self.apply(this.__code__, args, this.__globals__);
22086 }
22087 };
22088 context.set(stmt.name, func);
22089 } else if (stmt instanceof ast.ClassDef) {
22090 const bases = stmt.bases.map((base) => this.base(base, context));
22091 if (bases.length > 1) {
22092 throw new python.Error(`Unsupported multiple bases for class '${stmt.name}'.`);
22093 }
22094 const base = bases.length === 1 ? bases[0] : null;
22095 const name = `${context.get('__name__')}.${stmt.name}`;
22096 const value = this._createType(name, base ? class extends base {} : class {});
22097 value.__bases__ = bases;
22098 context.set(stmt.name, value);
22099 this.block(stmt.body, new python.Execution.Context(context.globals, value.prototype));
22100 } else if (stmt instanceof ast.AnnAssign) {
22101 const target = this.identifier(stmt.target, context);
22102 context.set(target, stmt.value ? this.expression(stmt.value, context) : undefined);
22103 } else if (stmt instanceof ast.Assign) {
22104 this.expression(stmt, context);
22105 } else if (stmt instanceof ast.If) {
22106 const test = this.expression(stmt.test, context);
22107 if (test === true || test) {
22108 const value = this.block(stmt.body, context);
22109 if (value !== undefined) {
22110 return value;
22111 }
22112 } else if (test === false) {
22113 if (stmt.orelse) {
22114 const value = this.block(stmt.orelse, context);
22115 if (value !== undefined) {
22116 return value;
22117 }
22118 }
22119 } else {

Callers 1

blockMethod · 0.80

Calls 13

expressionMethod · 0.80
mapMethod · 0.80
_createTypeMethod · 0.80
__import__Method · 0.80
splitMethod · 0.80
getMethod · 0.45
setMethod · 0.45
baseMethod · 0.45
blockMethod · 0.45
identifierMethod · 0.45
pushMethod · 0.45
__call__Method · 0.45

Tested by

no test coverage detected