Преглед на файлове

[python] use new @:import meta instead of boring __init__ methods

Dan Korostelev преди 11 години
родител
ревизия
83a9df8190

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

@@ -28,6 +28,7 @@ import python.lib.Builtin;
 	This class defines mathematical functions and constants.
 **/
 @:native("_hx_math")
+@:import("math")
 @:coreApi
 extern class Math
 {
@@ -310,7 +311,6 @@ extern class Math
 	}
 
 	static function __init__():Void {
-		python.Syntax.importAs("math", "_hx_math");
 		NEGATIVE_INFINITY = Builtin.float('-inf');
 		POSITIVE_INFINITY = Builtin.float('inf');
 		NaN = Builtin.float("nan");

+ 1 - 6
std/python/_std/String.hx

@@ -34,6 +34,7 @@ package;
 #if !macro
 import python.internal.StringImpl;
 #end
+@:import("builtins", "str")
 @:coreApi
 extern class String {
 
@@ -197,10 +198,4 @@ extern class String {
 	public static function fromCharCode( code : Int ) : String {
 		return StringImpl.fromCharCode(code);
 	}
-
-	@:keep static function __init__ ():Void {
-		python.Syntax.importFromAs("builtins", "str", "String");
-	}
-
-
 }

+ 1 - 6
std/python/lib/Bytes.hx

@@ -3,14 +3,9 @@ package python.lib;
 
 import python.lib.ByteArray;
 
+@:import("builtins", "bytes")
 extern class Bytes extends ByteArray {
 
 	//public function decode(encoding:String="utf-8", errors:String="strict"):String;
 
-	static function __init__ ():Void
-	{
-		Syntax.importFromAs("builtins", "bytes", "python.lib.Bytes");
-	}
-
-
 }

+ 1 - 3
std/python/lib/Codecs.hx

@@ -43,11 +43,9 @@ extern class StreamReaderWriterText implements StreamReader implements StreamWri
 }
 
 
+@:import("codecs")
 extern class Codecs {
 
 	public static function open(filename:String, mode:String, ?encoding:String, ?errors:String, ?buffering:Bool):StreamReaderWriterText;
 
-	static function __init__ ():Void {
-		Syntax.importAs("codecs", "python.lib.Codecs");
-	}
 }

+ 1 - 6
std/python/lib/Dict.hx

@@ -23,6 +23,7 @@ extern class DictView<T> {
 	}
 }
 
+@:import("builtins", "dict")
 extern class Dict <K, V>
 {
 	public function new ():Void;
@@ -63,12 +64,6 @@ extern class Dict <K, V>
 		return values().iter();
 	}
 	public function __iter__():NativeIterator<K>;
-
-	static function __init__ ():Void
-	{
-		Syntax.importFromAs("builtins", "dict", "python.lib.Dict");
-	}
-
 }
 
 class DictImpl {

+ 1 - 7
std/python/lib/Glob.hx

@@ -4,16 +4,10 @@ package python.lib;
 
 import python.NativeIterator;
 
+@:import("glob")
 extern class Glob {
 
 	public static function glob (pathname:String):Array<String>;
 	public static function iglob (pathname:String):NativeIterator<String>;
 
-
-
-	static function __init__ ():Void
-	{
-		Syntax.importAs("glob", "python.lib.Glob");
-	}
-
 }

+ 1 - 5
std/python/lib/Inspect.hx

@@ -3,13 +3,9 @@ package python.lib;
 
 import python.Syntax;
 
+@:import("inspect")
 extern class Inspect {
 
-	static function __init__ ():Void
-	{
-		python.Syntax.importAs("inspect", "python.lib.Inspect");
-	}
-
 	static function getmembers (value:Dynamic, ?filter:Dynamic->Bool):Bool;
 	static function ismethod (value:Dynamic):Bool;
 	static function isclass (value:Dynamic):Bool;

+ 1 - 4
std/python/lib/Json.hx

@@ -5,6 +5,7 @@ import python.KwArgs;
 import python.lib.Dict;
 import python.lib.Tuple.Tup2;
 
+@:import("json")
 extern class Json {
 
 
@@ -19,8 +20,4 @@ extern class Json {
 		cls:Null<Dynamic> = null, indent:Null<String> = null,
 		separators:Null<Tup2<String,String>>, /*default*/def:Null<Dynamic->String> = null, sort_keys:Bool=false, kw:KwArgs = null):String;
 
-	static function __init__ ():Void
-	{
-		python.Syntax.importAs("json", "python.lib.Json");
-	}
 }

+ 1 - 5
std/python/lib/Math.hx

@@ -1,5 +1,6 @@
 package python.lib;
 
+@:import("math")
 extern class Math {
 
 	public static function isnan (f:Float):Bool;
@@ -16,9 +17,4 @@ extern class Math {
 	static function atan(v:Float):Float;
 	static function atan2(y:Float, x:Float):Float;
 
-	static function __init__():Void {
-		python.Syntax.importAs("math", "python.lib.Math");
-
-	}
-
 }

+ 1 - 6
std/python/lib/Os.hx

@@ -30,6 +30,7 @@ extern class Stat {
 	@:optional public var st_type:Int;
 }
 
+@:import("os")
 extern class Os {
 
 	public static var environ : Dict<String, String>;
@@ -68,10 +69,4 @@ extern class Os {
 	public static function makedirs (path:String, mode : Int = 511 /* Oktal 777 */, exist_ok:Bool = false):Void;
 
 	public static function mkdir (path:String, mode : Int = 511 /* Oktal 777 */):Void;
-
-	static function __init__ ():Void
-	{
-		python.Syntax.importAs("os", "python.lib.Os");
-	}
-
 }

+ 1 - 4
std/python/lib/PPrint.hx

@@ -1,6 +1,7 @@
 
 package python.lib;
 
+@:import("pprint")
 extern class PPrint {
 
 
@@ -8,8 +9,4 @@ extern class PPrint {
 
 	public static function pformat(object:Dynamic, indent:Int=1, width:Int=80, depth:Int=null):String;
 
-	static function __init__ ():Void {
-		python.Syntax.importAs("pprint", "python.lib.PPrint");
-	}
-
 }

+ 1 - 5
std/python/lib/Random.hx

@@ -2,13 +2,9 @@
 package python.lib;
 
 
-
+@:import("random")
 extern class Random {
 
 	public static function random ():Float;
 
-	static function __init__ ():Void {
-		Syntax.importAs("random", "python.lib.Random");
-	}
-
 }

+ 1 - 5
std/python/lib/Re.hx

@@ -115,7 +115,7 @@ extern class Regex
 }
 
 
-
+@:import("re")
 extern class Re
 {
 
@@ -182,8 +182,4 @@ extern class Re
 	public static function escape(string:String):TODO;
 
 	public static function purge():Void;
-
-	static function __init__ ():Void {
-		python.Syntax.importAs("re", "python.lib.Re");
-	}
 }

+ 1 - 5
std/python/lib/Set.hx

@@ -4,6 +4,7 @@ package python.lib;
 import python.NativeIterator;
 import python.NativeIterable;
 
+@:import("builtins", "set")
 extern class Set <T>
 {
 	@:overload(function (?array:Array<T>):Void {})
@@ -29,11 +30,6 @@ extern class Set <T>
 		return python.Syntax.binop(this, "+", other);
 	}
 
-	static function __init__ ():Void
-	{
-		Syntax.importFromAs("builtins", "set", "python.lib.Set");
-	}
-
 	function __iter__ ():NativeIterator<T>;
 
 	public inline function iterator ():NativeIterator<T>

+ 1 - 5
std/python/lib/ShUtil.hx

@@ -2,7 +2,7 @@
 package python.lib;
 
 
-
+@:import("shutil")
 extern class ShUtil {
 
 	public static function rmtree(path:String, ?ignore_errors:Bool=false, ?onerror:python.lib.Exceptions.BaseException->Void):Void;
@@ -11,8 +11,4 @@ extern class ShUtil {
 
 	public static function copy (src:String, dst:String):Void;
 	public static function copy2 (src:String, dst:String):Void;
-
-	static function __init__ ():Void {
-		Syntax.importAs("shutil", "python.lib.ShUtil");
-	}
 }

+ 1 - 4
std/python/lib/Subprocess.hx

@@ -8,6 +8,7 @@ extern class StartupInfo {
 
 }
 
+@:import("subprocess")
 extern class Subprocess {
 
 	public static function STARTUPINFO():StartupInfo;
@@ -29,8 +30,4 @@ extern class Subprocess {
 
 	public static function call(args:Array<String>):Int;
 
-	static function __init__ ():Void
-	{
-		python.Syntax.importAs("subprocess", "python.lib.Subprocess");
-	}
 }

+ 1 - 5
std/python/lib/Sys.hx

@@ -10,6 +10,7 @@ import python.lib.Tuple.Tup3;
 extern class TB {}
 extern class Frame {}
 
+@:import("sys")
 extern class Sys {
 
 	public static var argv(default, never):Array<String>;
@@ -31,9 +32,4 @@ extern class Sys {
 
 	public static function exc_info<T:BaseException>():Tup3<Class<T>, T, TB>;
 
-	static function __init__ ():Void
-	{
-		python.Syntax.importAs("sys", "python.lib.Sys");
-	}
-
 }

+ 1 - 3
std/python/lib/Tempfile.hx

@@ -1,11 +1,9 @@
 
 package python.lib;
 
+@:import("tempfile")
 extern class Tempfile {
 
 	public static function gettempdir():String;
-	static function __init__ ():Void {
-		Syntax.importAs("tempfile", "python.lib.Tempfile");
-	}
 
 }

+ 1 - 5
std/python/lib/ThreadLowLevel.hx

@@ -5,13 +5,9 @@ import python.lib.Tuple;
 
 private typedef TODO = Dynamic;
 
+@:import("_thread")
 extern class ThreadLowLevel {
 
 	public static function start_new_thread(f:Void->Void, args:Tuple<Dynamic>):TODO;
 
-	static function __init__ ():Void
-	{
-		python.Syntax.importAs("_thread", "python.lib.ThreadLowLevel");
-	}
-
 }

+ 1 - 4
std/python/lib/Time.hx

@@ -1,13 +1,10 @@
 
 package python.lib;
 
+@:import("time")
 extern class Time {
 
 	public static function time ():Float;
 	public static function clock ():Float;
 	public static function sleep (t:Float):Void;
-	static function __init__ ():Void
-	{
-		python.Syntax.importAs("time", "python.lib.Time");
-	}
 }

+ 1 - 4
std/python/lib/Traceback.hx

@@ -4,15 +4,12 @@ import python.lib.Sys;
 import python.lib.Sys.Frame;
 import python.lib.Tuple;
 
-
+@:import("traceback")
 extern class Traceback {
 
 	public static function extract_stack(?f:Frame, ?limit:Int):Array<StackItem>;
 	public static function extract_tb(tb:Sys.TB, ?limit:Int):Array<StackItem>;
 
-	static function __init__ ():Void {
-		python.Syntax.importAs("traceback", "python.lib.Traceback");
-	}
 }
 
 private typedef StackItem = Tup4<String, Int, String, String>;

+ 1 - 5
std/python/lib/datetime/DateTime.hx

@@ -2,6 +2,7 @@
 package python.lib.datetime;
 
 
+@:import("datetime", "datetime")
 extern class DateTime {
 
 	public function new (year:Int, month:Int, day:Int, hour:Int=0, minute:Int=0, second:Int=0, microsecond:Int=0, tzinfo:TzInfo=null);
@@ -37,9 +38,4 @@ extern class DateTime {
 
 	// python 3.3
 	public function timestamp ():Float;
-
-	static function __init__ ():Void
-	{
-		python.Syntax.importFromAs("datetime", "datetime", "python.lib.datetime.DateTime");
-	}
 }

+ 1 - 5
std/python/lib/datetime/TimeDelta.hx

@@ -1,6 +1,7 @@
 
 package python.lib.datetime;
 
+@:import("datetime", "timedelta")
 extern class TimeDelta {
 
 	public static var min : TimeDelta;
@@ -14,9 +15,4 @@ extern class TimeDelta {
 	var microseconds : Int;
 
 	public function new(days:Int = 0, seconds:Int = 0, microseconds:Int = 0, milliseconds:Int = 0, minutes:Int = 0, hours:Int = 0, weeks:Int = 0):Void;
-
-	static function __init__ ():Void
-	{
-		python.Syntax.importFromAs("datetime", "timedelta", "python.lib.datetime.TimeDelta");
-	}
 }

+ 1 - 4
std/python/lib/datetime/Timezone.hx

@@ -1,11 +1,8 @@
 
 package python.lib.datetime;
 
+@:import("datetime", "timezone")
 extern class Timezone extends TzInfo {
 
 	public static var utc(default, never):TzInfo;
-	static function __init__ ():Void
-	{
-		python.Syntax.importFromAs("datetime", "timezone", "python.lib.datetime.Timezone");
-	}
 }

+ 2 - 7
std/python/lib/datetime/TzInfo.hx

@@ -1,11 +1,6 @@
 
 package python.lib.datetime;
 
+@:import("datetime", "tzinfo")
 extern class TzInfo {
-
-
-	static function __init__ ():Void
-	{
-		python.Syntax.importFromAs("datetime", "tzinfo", "python.lib.datetime.TzInfo");
-	}
-}
+}

+ 1 - 5
std/python/lib/io/BytesIO.hx

@@ -1,13 +1,9 @@
 
 package python.lib.io;
 
+@:import("io", "BytesIO")
 extern class BytesIO extends python.lib.io.BufferedIOBase {
 
 	public function new (base:python.lib.io.IOBase);
 
-	static function __init__ ():Void
-	{
-		python.Syntax.importFromAs("io", "BytesIO", "python.lib.io.BytesIO");
-	}
-
 }

+ 1 - 6
std/python/lib/io/StringIO.hx

@@ -4,14 +4,9 @@ package python.lib.io;
 import python.lib.io.TextIOBase;
 import python.Syntax;
 
+@:import("io", "StringIO")
 extern class StringIO extends TextIOBase
 {
 	public function new (?s:String):Void;
 	public function getvalue():String;
-
-
-
-	static function __init__ ():Void {
-		Syntax.importFromAs("io", "StringIO", "python.lib.io.StringIO");
-	}
 }

+ 2 - 5
std/python/lib/json/JSONEncoder.hx

@@ -1,9 +1,6 @@
 
 package python.lib.json;
 
+@:import("json", "JSONEncoder")
 extern class JSONEncoder {
-
-	static function __init__ ():Void {
-		python.Syntax.importFromAs("json", "JSONEncoder", "python.lib.json.JSONEncoder");
-	}
-}
+}

+ 2 - 10
std/python/lib/net/Socket.hx

@@ -33,24 +33,16 @@ typedef Selectable = {
 }
 
 @:native("select")
+@:import("select")
 extern class Select {
 
-    static function __init__ ():Void
-    {
-        Syntax.importModule("select");
-    }
-
     static function select<T>(reads:Array<T>,writes:Array<T>,xs:Array<T>,timeout:Float):Tup3<Array<T>,Array<T>,Array<T>>;
 
 }
 
+@:import("socket", "socket")
 extern class Socket {
 
-    static function __init__ ():Void
-    {
-        Syntax.importFromAs("socket", "socket", "python.lib.net.Socket");
-    }
-
     static var AF_APPLETALK:Int;
     static var AF_ASH:Int;
     static var AF_ATMPVC:Int;

+ 1 - 5
std/python/lib/os/Path.hx

@@ -3,6 +3,7 @@ package python.lib.os;
 
 import python.lib.Tuple;
 
+@:import("os", "path")
 extern class Path {
 
 	public static var sep : String;
@@ -60,9 +61,4 @@ extern class Path {
 
 	public static function supports_unicode_filenames ():Bool;
 
-
-	static function __init__ ():Void
-	{
-		python.Syntax.importFromAs("os", "path", "python.lib.os.Path");
-	}
 }

+ 1 - 5
std/python/lib/subprocess/Popen.hx

@@ -22,6 +22,7 @@ typedef PopenOptions = {
 	?creationflags : Int,
 }
 
+@:import("subprocess", "Popen")
 extern class Popen {
 
 	public static inline function create (args:Array<String>, o:PopenOptions):Popen {
@@ -72,9 +73,4 @@ extern class Popen {
 
 	public function communicate (input:Bytes = null, timeout:Null<Int> = null):Tup2<Bytes, Bytes>;
 
-	static function __init__ ():Void
-	{
-		python.Syntax.importFromAs("subprocess", "Popen", "python.lib.subprocess.Popen");
-	}
-
 }

+ 1 - 6
std/python/lib/threading/Thread.hx

@@ -1,11 +1,6 @@
 
 package python.lib.threading;
 
+@:import("threading", "Thread")
 extern class Thread {
-
-	static function __init__ ():Void
-	{
-		python.Syntax.importFromAs("threading","Thread", "python.lib.thrading.Thread");
-	}
-
 }

+ 3 - 15
std/python/lib/xml/etree/ElementTree.hx

@@ -10,6 +10,7 @@ extern class XMLParser {
 
 }
 
+@:import("xml.etree.ElementTree", "Element")
 extern class Element {
 	public function getroot ():ElementTree;
 	public var tag:String;
@@ -29,13 +30,9 @@ extern class Element {
 	public function iterfind (tag:String, namespaces:Dict<String,String> = null):NativeIterator<Element>;
 	public function find (match:String, namespaces:Dict<String,String> = null):Null<Element>;
 	public function findall (match:String, namespaces:Dict<String,String> = null):Array<Element>;
-
-	static function __init__ ():Void
-	{
-		Syntax.importFromAs("xml.etree.ElementTree", "Element", "python.lib.xml.etree.Element");
-	}
 }
 
+@:import("xml.etree.ElementTree")
 extern class ElementTree {
 
 
@@ -46,13 +43,4 @@ extern class ElementTree {
 	public function iter (tag:String):NativeIterable<Element>;
 	public function find (match:String, namespaces:Dict<String,String> = null):Null<Element>;
 	public function getroot ():Element;
-
-
-
-
-	static function __init__ ():Void
-	{
-		Syntax.importAs("xml.etree.ElementTree", "python.lib.xml.etree.ElementTree");
-	}
-
-}
+}