浏览代码

[python] support @:python metadata for classes and print a proper error instead of assertion failure

Dan Korostelev 5 年之前
父节点
当前提交
562ed0bc84
共有 1 个文件被更改,包括 7 次插入5 次删除
  1. 7 5
      src/generators/genpy.ml

+ 7 - 5
src/generators/genpy.ml

@@ -1872,12 +1872,12 @@ module Generator = struct
 	(* Generating functions *)
 
 	let gen_py_metas ctx metas indent =
-		List.iter (fun (n,el,_) ->
+		List.iter (fun (n,el,p) ->
 			match el with
-				| [EConst(String(s,_)),_] ->
-					print ctx "%s@%s\n" indent s
-				| _ ->
-					assert false
+			| [EConst(String(s,_)),_] ->
+				print ctx "%s@%s\n" indent s
+			| _ ->
+				abort "@:python metadata must have a string literal argument" p
 		) metas
 
 	let gen_expr ctx e field indent =
@@ -2110,6 +2110,8 @@ module Generator = struct
 			newline ctx;
 			newline ctx;
 			newline ctx;
+			let py_metas = filter_py_metas c.cl_meta in
+			gen_py_metas ctx py_metas "";
 			print ctx "class %s" p;
 			(match p_super with Some p -> print ctx "(%s)" p | _ -> ());
 			spr ctx ":";