Explorar el Código

[python] add description for VarArgs and KwArgs

Dan Korostelev hace 10 años
padre
commit
0f4f6af45d
Se han modificado 2 ficheros con 35 adiciones y 19 borrados
  1. 20 13
      std/python/KwArgs.hx
  2. 15 6
      std/python/VarArgs.hx

+ 20 - 13
std/python/KwArgs.hx

@@ -2,30 +2,37 @@ package python;
 
 import python.lib.Dict;
 
-abstract KwArgs<T:{}> (Dict<String, Dynamic>)
-{
-	inline function new (d:Dict<String, Dynamic>) this = d;
+/**
+	This type represents python `**kwargs` feature, supporting
+	passing named arguments to a function.
 
-	@:to public inline function toDict ():Dict<String, Dynamic>
-	{
+	Example:
+
+        function f(kwargs:KwArgs<{a:Int}>) {}
+        f({a: 10});
+**/
+abstract KwArgs<T:{}>(Dict<String,Dynamic>) {
+	inline function new (d:Dict<String,Dynamic>) {
+		this = d;
+	}
+
+	@:to public inline function toDict():Dict<String,Dynamic> {
 		return this;
 	}
-	@:from static inline function fromDict (d:Dict<String, Dynamic>):KwArgs<Dynamic>
-	{
+
+	@:from static inline function fromDict(d:Dict<String,Dynamic>):KwArgs<Dynamic> {
 		return new KwArgs(d);
 	}
-	@:from static inline function fromT <T:{}>(d:T):KwArgs<T>
-	{
+
+	@:from static inline function fromT<T:{}>(d:T):KwArgs<T> {
 		return new KwArgs(Lib.anonAsDict(d));
 	}
 
-	public function typed ():T
-	{
+	public inline function typed():T {
 		return Lib.dictAsAnon(toDict());
 	}
 
-	public function get <V>(key:String, def:V):V
-	{
+	public inline function get<V>(key:String, def:V):V {
 		return this.get(key, def);
 	}
 }

+ 15 - 6
std/python/VarArgs.hx

@@ -1,19 +1,28 @@
 package python;
 
-import python.lib.Builtin;
+import python.lib.Builtin.list;
 
+/**
+	This type represents python `*args` feature, supporting
+	passing arbitrary number of arguments to a function.
+
+	Example:
+
+		function f(args:VarArgs<Int>) {}
+		f([1, 2, 3]);
+**/
 @:analyzer(no_simplification)
 abstract VarArgs<T>(Dynamic) {
 	inline function new(d:Array<T>) {
-        this = d;
-    }
+		this = d;
+	}
 
 	inline function raw():Dynamic {
-        return this;
-    }
+		return this;
+	}
 
 	@:to public inline function toArray():Array<T> {
-		return if (!Std.is(raw(), Array)) Builtin.list(raw()) else (raw() : Array<T>);
+		return if (!Std.is(raw(), Array)) list(raw()) else (raw() : Array<T>);
 	}
 
 	@:from static inline function fromArray<T>(d:Array<T>):VarArgs<T> {