Explorar el Código

[python] support importing nested classes

Dan Korostelev hace 11 años
padre
commit
f167fe17c4
Se han modificado 1 ficheros con 7 adiciones y 2 borrados
  1. 7 2
      genpy.ml

+ 7 - 2
genpy.ml

@@ -1723,9 +1723,14 @@ module Generator = struct
 					| [(EConst(String(module_name)), _)] ->
 						(* importing whole module *)
 						"import " ^ module_name ^ " as " ^ class_name
+
 					| [(EConst(String(module_name)), _); (EConst(String(object_name)), _)] ->
-						(* importing a class from a module *)
-						"from " ^ module_name ^ " import " ^ object_name ^ " as " ^ class_name;
+						if String.contains object_name '.' then
+							(* importing nested class *)
+							"import " ^ module_name ^ "; " ^ class_name ^ " = " ^ module_name ^ "." ^ object_name
+						else
+							(* importing a class from a module *)
+							"from " ^ module_name ^ " import " ^ object_name ^ " as " ^ class_name
 					| _ ->
 						error "Unsupported @:import format" mp
 				in