ソースを参照

[python] support typed VarArgs similar to KwArgs (see #3879)

Dan Korostelev 10 年 前
コミット
d4458474db

+ 10 - 13
std/python/VarArgs.hx

@@ -1,25 +1,22 @@
-
 package python;
 
 import python.lib.Builtin;
 
 @:analyzer(no_simplification)
-abstract VarArgs (Dynamic)
-{
-	inline function new (d:Array<Dynamic>) this = d;
-
+abstract VarArgs<T>(Dynamic) {
+	inline function new(d:Array<T>) {
+        this = d;
+    }
 
-	inline function raw ():Dynamic {
-		return this;
-	}
+	inline function raw():Dynamic {
+        return this;
+    }
 
-	@:to public inline function toArray ():Array<Dynamic>
-	{
-		return if (!Std.is(raw(), Array)) Builtin.list(raw()) else (raw():Array<Dynamic>);
+	@:to public inline function toArray():Array<T> {
+		return if (!Std.is(raw(), Array)) Builtin.list(raw()) else (raw() : Array<T>);
 	}
 
-	@:from static inline function fromArray (d:Array<Dynamic>):VarArgs
-	{
+	@:from static inline function fromArray<T>(d:Array<T>):VarArgs<T> {
 		return new VarArgs(d);
 	}
 }

+ 1 - 1
std/python/_std/Reflect.hx

@@ -127,7 +127,7 @@ class Reflect {
 
 	@:overload(function( f : Array<Dynamic> -> Void ) : Dynamic {})
 	public static function makeVarArgs( f : Array<Dynamic> -> Dynamic ) : Dynamic {
-		return function (v:VarArgs) {
+		return function (v:VarArgs<Dynamic>) {
 			return f(v);
 		}
 	}

+ 4 - 4
tests/unit/src/unit/TestPython.hx

@@ -216,7 +216,7 @@ class TestPython extends Test {
 	}
 
 	function testKwArgsAfterVarArgs () {
-		function test (va:VarArgs, kw:KwArgs<Dynamic>) {
+		function test (va:VarArgs<Dynamic>, kw:KwArgs<Dynamic>) {
 			var a = va.toArray();
 
 			eq(1,a[0]);
@@ -229,7 +229,7 @@ class TestPython extends Test {
 	}
 
 	function testOptionalVarArgs () {
-		function test (?va:VarArgs, ?kw:KwArgs<Dynamic>) {
+		function test (?va:VarArgs<Dynamic>, ?kw:KwArgs<Dynamic>) {
 			var a = va.toArray();
 
 			eq(0,a.length);
@@ -243,7 +243,7 @@ class TestPython extends Test {
 	}
 
 	function testOptionalKwArgsAfterOptionalVarArgs () {
-		function test (?va:VarArgs, ?kw:KwArgs<Dynamic>) {
+		function test (?va:VarArgs<Dynamic>, ?kw:KwArgs<Dynamic>) {
 			var a = va.toArray();
 
 			eq(1,a[0]);
@@ -254,7 +254,7 @@ class TestPython extends Test {
 		var x = [1,2];
 		test(x);
 
-		function test (?va:VarArgs, ?kw:KwArgs<Dynamic>) {
+		function test (?va:VarArgs<Dynamic>, ?kw:KwArgs<Dynamic>) {
 			var a = va.toArray();
 			eq(0,a.length);
 			eq(1, kw.get("a",null));

+ 1 - 1
tests/unit/src/unit/issues/Issue2980.hx

@@ -4,7 +4,7 @@ class Issue2980 extends Test {
 
 	#if python
 	function a(?args:python.KwArgs<Dynamic>) {}
-    function b(?args:python.VarArgs) {}
+    function b(?args:python.VarArgs<Dynamic>) {}
 
 	function test() {
 		a();