From 81f1f788d2c87ce84d136dcba61d0808833080bb Mon Sep 17 00:00:00 2001 From: Haoxiang Fei Date: Sat, 8 Nov 2025 13:58:54 +0800 Subject: [PATCH 1/2] chore: format --- bool.mbt | 18 ++-- callable.mbt | 12 ++- cpython/abstract.mbt | 216 ++++++++++++++++++++++++++++--------------- cpython/cell.mbt | 2 +- cpython/ceval.mbt | 2 +- cpython/class.mbt | 2 +- cpython/code.mbt | 2 +- cpython/codecs.mbt | 2 +- cpython/context.mbt | 2 +- dict.mbt | 48 ++++++---- float.mbt | 15 ++- integer.mbt | 15 ++- list.mbt | 33 ++++--- main/main.mbt | 2 +- module.mbt | 13 ++- obj.mbt | 2 +- str.mbt | 12 ++- test/object_test.mbt | 18 ++-- time/lib.mbt | 29 ++++-- tkinter/tkinter.mbt | 8 +- traits.mbt | 3 +- tuple.mbt | 24 +++-- turtle/color.mbt | 6 +- turtle/lib.mbt | 20 ++-- turtle/pen2.mbt | 123 +++++++++++++++--------- turtle/shape.mbt | 3 +- utils.mbt | 3 +- 27 files changed, 412 insertions(+), 223 deletions(-) diff --git a/bool.mbt b/bool.mbt index ec9cef7..317fd7b 100644 --- a/bool.mbt +++ b/bool.mbt @@ -7,7 +7,8 @@ pub struct PyBool { priv obj : PyObject } -///| Create a python boolean object from a python object. +///| +/// Create a python boolean object from a python object. /// If the object is not a boolean, it will raise a TypeMisMatchError. pub fn PyBool::create(obj : PyObject) -> PyBool raise PyRuntimeError { guard obj.is_bool() else { raise TypeMisMatchError } @@ -19,7 +20,8 @@ fn PyBool::create_unchecked(obj : PyObject) -> PyBool { PyBool::{ obj, } } -///| Create a python boolean object from a python object reference. +///| +/// Create a python boolean object from a python object reference. /// If the object is not a boolean, it will raise a TypeMisMatchError. pub fn PyBool::create_by_ref( obj_ref : @cpython.PyObjectRef, @@ -38,7 +40,8 @@ pub fn PyBool::dump(self : PyBool) -> Unit { self.obj.dump() } -///| Create a python boolean object from moonbit bool. +///| +/// Create a python boolean object from moonbit bool. /// /// ## Example /// @@ -61,7 +64,8 @@ pub fn PyBool::from(value : Bool) -> PyBool { PyBool::create_by_ref_unchecked(obj_ref) } -///| Return `true` if it is true, using python interpreter. +///| +/// Return `true` if it is true, using python interpreter. /// /// ## Example /// @@ -82,7 +86,8 @@ pub fn PyBool::to_bool(self : PyBool) -> Bool { self.is_true() } -///| Return `true` if it is false, using python interpreter. +///| +/// Return `true` if it is false, using python interpreter. /// /// ## Example /// @@ -97,7 +102,8 @@ pub fn PyBool::is_false(self : PyBool) -> Bool { self.is_true() |> not } -///| Return the reverse of the boolean value. +///| +/// Return the reverse of the boolean value. /// /// ## Example /// diff --git a/callable.mbt b/callable.mbt index f105417..3479523 100644 --- a/callable.mbt +++ b/callable.mbt @@ -7,7 +7,8 @@ pub struct PyCallable { priv obj : PyObject } -///| Create a python callable object from a PyObject. +///| +/// Create a python callable object from a PyObject. /// If the object is not callable, a TypeMisMatchError is raised. pub fn PyCallable::create(obj : PyObject) -> PyCallable raise PyRuntimeError { guard obj.is_callable() else { raise TypeMisMatchError } @@ -19,7 +20,8 @@ fn PyCallable::create_unchecked(obj : PyObject) -> PyCallable { PyCallable::{ obj, } } -///| Create a python callable object from a PyObjectRef. +///| +/// Create a python callable object from a PyObjectRef. /// If the object is not callable, a TypeMisMatchError is raised. pub fn PyCallable::create_by_ref( obj : @cpython.PyObjectRef, @@ -49,9 +51,9 @@ pub fn PyCallable::dump(self : PyCallable) -> Unit { ///| pub fn PyCallable::invoke( self : PyCallable, - args~ : PyTuple = PyTuple::new(0), - kwargs~ : PyDict = PyDict::new(), - print_err~ : Bool = false, + args? : PyTuple = PyTuple::new(0), + kwargs? : PyDict = PyDict::new(), + print_err? : Bool = false, ) -> PyObjectEnum? raise PyRuntimeError { let obj_ref = if kwargs.len() > 0 { @cpython.py_object_call(self.obj_ref(), args.obj_ref(), kwargs.obj_ref()) diff --git a/cpython/abstract.mbt b/cpython/abstract.mbt index 2fbe15a..6b16c95 100644 --- a/cpython/abstract.mbt +++ b/cpython/abstract.mbt @@ -1,6 +1,7 @@ // Abstract -///| Call a callable Python object 'callable' with arguments given by the +///| +/// Call a callable Python object 'callable' with arguments given by the /// tuple 'args' and keywords arguments given by the dictionary 'kwargs'. /// /// 'args' must not be NULL, use an empty tuple if no arguments are @@ -15,7 +16,8 @@ pub extern "C" fn py_object_call( kwargs : PyObjectRef, ) -> PyObjectRef = "PyObject_Call" -///| Call a callable Python object 'callable', with arguments given by the +///| +/// Call a callable Python object 'callable', with arguments given by the /// tuple 'args'. If no arguments are needed, then 'args' can be NULL. /// /// Returns the result of the call on success, or NULL on failure. @@ -28,7 +30,8 @@ pub extern "C" fn py_object_call_object( args : PyObjectRef, ) -> PyObjectRef = "PyObject_CallObject" -///| Get the type of an object. +///| +/// Get the type of an object. /// /// On success, returns a type object corresponding to the object type of object /// 'o'. On failure, returns NULL. @@ -37,7 +40,8 @@ pub extern "C" fn py_object_call_object( #owned(obj) pub extern "C" fn py_object_type(obj : PyObjectRef) -> PyObjectRef = "PyObject_Type" -///| Return the size of object 'o'. If the object 'o' provides both sequence and +///| +/// Return the size of object 'o'. If the object 'o' provides both sequence and /// mapping protocols, the sequence size is returned. /// /// On error, -1 is returned. @@ -46,7 +50,8 @@ pub extern "C" fn py_object_type(obj : PyObjectRef) -> PyObjectRef = "PyObject_T #owned(obj) pub extern "C" fn py_object_size(obj : PyObjectRef) -> UInt64 = "PyObject_Size" -///| Return element of 'o' corresponding to the object 'key'. Return NULL +///| +/// Return element of 'o' corresponding to the object 'key'. Return NULL /// on failure. /// /// This is the equivalent of the Python expression: o[key] */ @@ -56,7 +61,8 @@ pub extern "C" fn py_object_get_item( key : PyObjectRef, ) -> PyObjectRef = "PyObject_GetItem" -///| Map the object 'key' to the value 'v' into 'o'. +///| +/// Map the object 'key' to the value 'v' into 'o'. /// /// Raise an exception and return -1 on failure; return 0 on success. /// @@ -68,7 +74,8 @@ pub extern "C" fn py_object_set_item( value : PyObjectRef, ) -> Int = "py_object_SetItem" -///| Remove the mapping for the string 'key' from the object 'o'. +///| +/// Remove the mapping for the string 'key' from the object 'o'. /// Returns -1 on failure. /// /// This is equivalent to the Python statement: del o[key]. @@ -78,7 +85,8 @@ pub extern "C" fn py_object_del_item_string( key : CStr, ) -> Int = "PyObject_DelItemString" -///| Delete the mapping for the object 'key' from the object 'o'. +///| +/// Delete the mapping for the object 'key' from the object 'o'. /// Returns -1 on failure. /// /// This is the equivalent of the Python statement: del o[key]. @@ -88,7 +96,8 @@ pub extern "C" fn py_object_del_item( key : PyObjectRef, ) -> Int = "PyObject_DelItem" -///| Takes an arbitrary object and returns the result of calling +///| +/// Takes an arbitrary object and returns the result of calling /// obj.__format__(format_spec). #owned(obj, format_spec) pub extern "C" fn pyobkect_format( @@ -96,19 +105,22 @@ pub extern "C" fn pyobkect_format( format_spec : PyObjectRef, ) -> PyObjectRef = "PyObject_Format" -///| Takes an object and returns an iterator for it. +///| +/// Takes an object and returns an iterator for it. /// This is typically a new iterator but if the argument is an iterator, this /// returns itself. */ #owned(obj) pub extern "C" fn py_object_get_iter(obj : PyObjectRef) -> PyObjectRef = "PyObject_GetIter" -///| Returns 1 if the object 'obj' provides iterator protocols, and 0 otherwise. +///| +/// Returns 1 if the object 'obj' provides iterator protocols, and 0 otherwise. /// /// This function always succeeds. */ #owned(obj) pub extern "C" fn pyiter_check(obj : PyObjectRef) -> Int = "PyIter_Check" -///| Takes an iterator object and calls its tp_iternext slot, +///| +/// Takes an iterator object and calls its tp_iternext slot, /// returning the next value. /// /// If the iterator is exhausted, this returns NULL without setting an @@ -118,13 +130,15 @@ pub extern "C" fn pyiter_check(obj : PyObjectRef) -> Int = "PyIter_Check" #owned(iter) pub extern "C" fn pyiter_next(iter : PyObjectRef) -> PyObjectRef = "PyIter_Next" -///| Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. +///| +/// Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. /// /// This function always succeeds. */ #owned(obj) pub extern "C" fn pynumber_check(obj : PyObjectRef) -> Int = "PyNumber_Check" -///| Returns the result of adding o1 and o2, or NULL on failure. +///| +/// Returns the result of adding o1 and o2, or NULL on failure. /// /// This is the equivalent of the Python expression: o1 + o2. */ #owned(obj1, obj2) @@ -133,7 +147,8 @@ pub extern "C" fn pynumber_add( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Add" -///| Returns the result of subtracting o2 from o1, or NULL on failure. +///| +/// Returns the result of subtracting o2 from o1, or NULL on failure. /// /// This is the equivalent of the Python expression: o1 - o2. */ #owned(obj1, obj2) @@ -142,7 +157,8 @@ pub extern "C" fn pynumber_subtract( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Subtract" -///| Returns the result of multiplying o1 and o2, or NULL on failure. +///| +/// Returns the result of multiplying o1 and o2, or NULL on failure. /// /// This is the equivalent of the Python expression: o1 * o2. */ #owned(obj1, obj2) @@ -151,7 +167,8 @@ pub extern "C" fn pynumber_multiply( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Multiply" -///| Returns the result of dividing o1 by o2 giving an integral result, +///| +/// Returns the result of dividing o1 by o2 giving an integral result, /// or NULL on failure. /// /// This is the equivalent of the Python expression: o1 // o2. */ @@ -161,7 +178,8 @@ pub extern "C" fn pynumber_floor_divide( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_FloorDivide" -///| Returns the result of dividing o1 by o2 giving a float result, or NULL on +///| +/// Returns the result of dividing o1 by o2 giving a float result, or NULL on /// failure. /// /// This is the equivalent of the Python expression: o1 / o2. @@ -171,7 +189,8 @@ pub extern "C" fn pynumber_true_divide( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_TrueDivide" -///| Returns the remainder of dividing o1 by o2, or NULL on failure. +///| +/// Returns the remainder of dividing o1 by o2, or NULL on failure. /// /// This is the equivalent of the Python expression: o1 % o2. #owned(obj1, obj2) @@ -180,7 +199,8 @@ pub extern "C" fn pynumber_remainder( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Remainder" -///| See the built-in function divmod. +///| +/// See the built-in function divmod. /// /// Returns NULL on failure. /// @@ -191,7 +211,8 @@ pub extern "C" fn pynumber_divmod( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Divmod" -///| See the built-in function pow. Returns NULL on failure. +///| +/// See the built-in function pow. Returns NULL on failure. /// /// This is the equivalent of the Python expression: pow(o1, o2, o3), /// where o3 is optional. @@ -202,31 +223,36 @@ pub extern "C" fn pynumber_power( obj3 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Power" -///| Returns the negation of o on success, or NULL on failure. +///| +/// Returns the negation of o on success, or NULL on failure. /// /// This is the equivalent of the Python expression: -o. #owned(obj) pub extern "C" fn pynumber_negative(obj : PyObjectRef) -> PyObjectRef = "PyNumber_Negative" -///| Returns the positive of o on success, or NULL on failure. +///| +/// Returns the positive of o on success, or NULL on failure. /// /// This is the equivalent of the Python expression: +o. #owned(obj) pub extern "C" fn pynumber_positive(obj : PyObjectRef) -> PyObjectRef = "PyNumber_Positive" -///| Returns the absolute value of 'o', or NULL on failure. +///| +/// Returns the absolute value of 'o', or NULL on failure. /// /// This is the equivalent of the Python expression: abs(o). #owned(obj) pub extern "C" fn pynumber_absolute(obj : PyObjectRef) -> PyObjectRef = "PyNumber_Absolute" -///| Returns the bitwise negation of 'o' on success, or NULL on failure. +///| +/// Returns the bitwise negation of 'o' on success, or NULL on failure. /// /// This is the equivalent of the Python expression: ~o. #owned(obj) pub extern "C" fn pynumber_invert(obj : PyObjectRef) -> PyObjectRef = "PyNumber_Invert" -///| Returns the result of left shifting o1 by o2 on success, or NULL on failure. +///| +/// Returns the result of left shifting o1 by o2 on success, or NULL on failure. /// /// This is the equivalent of the Python expression: o1 << o2. #owned(obj1, obj2) @@ -235,7 +261,8 @@ pub extern "C" fn pynumber_lshift( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Lshift" -///| Returns the result of right shifting o1 by o2 on success, or NULL on +///| +/// Returns the result of right shifting o1 by o2 on success, or NULL on /// failure. /// /// This is the equivalent of the Python expression: o1 >> o2. @@ -245,7 +272,8 @@ pub extern "C" fn pynumber_rshift( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Rshift" -///| Returns the result of bitwise and of o1 and o2 on success, or NULL on +///| +/// Returns the result of bitwise and of o1 and o2 on success, or NULL on /// failure. /// /// This is the equivalent of the Python expression: o1 & o2. @@ -255,7 +283,8 @@ pub extern "C" fn pynumber_and( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_And" -///| Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure. +///| +/// Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure. /// /// This is the equivalent of the Python expression: o1 ^ o2. #owned(obj1, obj2) @@ -264,7 +293,8 @@ pub extern "C" fn pynumber_xor( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Xor" -///| Returns the result of bitwise or on o1 and o2 on success, or NULL on +///| +/// Returns the result of bitwise or on o1 and o2 on success, or NULL on /// failure. /// /// This is the equivalent of the Python expression: o1 | o2. @@ -274,17 +304,20 @@ pub extern "C" fn pynumber_or( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_Or" -///| Returns 1 if obj is an index integer (has the nb_index slot of the +///| +/// Returns 1 if obj is an index integer (has the nb_index slot of the /// tp_as_number structure filled in), and 0 otherwise. #owned(obj) pub extern "C" fn pyindex_check(obj : PyObjectRef) -> Int = "PyIndex_Check" -///| Returns the object 'o' converted to a Python int, or NULL with an exception +///| +/// Returns the object 'o' converted to a Python int, or NULL with an exception /// raised on failure. #owned(obj) pub extern "C" fn pynumber_index(obj : PyObjectRef) -> PyObjectRef = "PyNumber_Index" -///| Returns the object 'o' converted to Py_ssize_t by going through +///| +/// Returns the object 'o' converted to Py_ssize_t by going through /// PyNumber_Index() first. /// /// If an overflow error occurs while converting the int to Py_ssize_t, then the @@ -296,21 +329,24 @@ pub extern "C" fn pynumber_as_ssize_t( exc : PyObjectRef, ) -> Int = "PyNumber_AsSsize_t" -///| Returns the object 'o' converted to an integer object on success, or NULL +///| +/// Returns the object 'o' converted to an integer object on success, or NULL /// on failure. /// /// This is the equivalent of the Python expression: int(o). #owned(obj) pub extern "C" fn pynumber_long(obj : PyObjectRef) -> PyObjectRef = "PyNumber_Long" -///| Returns the object 'o' converted to a float object on success, or NULL +///| +/// Returns the object 'o' converted to a float object on success, or NULL /// on failure. /// /// This is the equivalent of the Python expression: float(o). #owned(obj) pub extern "C" fn pynumber_float(obj : PyObjectRef) -> PyObjectRef = "PyNumber_Float" -///| Returns the result of adding o2 to o1, possibly in-place, or NULL +///| +/// Returns the result of adding o2 to o1, possibly in-place, or NULL /// on failure. /// /// This is the equivalent of the Python expression: o1 += o2. @@ -320,7 +356,8 @@ pub extern "C" fn pynumber_inplace_add( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceAdd" -///| Returns the result of subtracting o2 from o1, possibly in-place or +///| +/// Returns the result of subtracting o2 from o1, possibly in-place or /// NULL on failure. /// /// This is the equivalent of the Python expression: o1 -= o2. @@ -330,7 +367,8 @@ pub extern "C" fn pynumber_inplace_subtract( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceSubtract" -///| Returns the result of multiplying o1 by o2, possibly in-place, or NULL on +///| +/// Returns the result of multiplying o1 by o2, possibly in-place, or NULL on /// failure. /// /// This is the equivalent of the Python expression: o1 *= o2. @@ -347,7 +385,8 @@ pub extern "C" fn pynumber_inplace_floor_divide( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceFloorDivide" -///| Returns the result of dividing o1 by o2 giving a float result, possibly +///| +/// Returns the result of dividing o1 by o2 giving a float result, possibly /// in-place, or null on failure. /// /// This is the equivalent of the Python expression: o1 /= o2. @@ -357,7 +396,8 @@ pub extern "C" fn pynumber_inplace_true_divide( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceTrueDivide" -///| Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on +///| +/// Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on /// failure. /// /// This is the equivalent of the Python expression: o1 %= o2. @@ -367,7 +407,8 @@ pub extern "C" fn pynumber_inplace_remainder( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceRemainder" -///| Returns the result of raising o1 to the power of o2, possibly in-place, +///| +/// Returns the result of raising o1 to the power of o2, possibly in-place, /// or NULL on failure. /// /// This is the equivalent of the Python expression: o1 **= o2, @@ -379,7 +420,8 @@ pub extern "C" fn pynumber_inplace_power( obj3 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlacePower" -///| Returns the result of left shifting o1 by o2, possibly in-place, or NULL +///| +/// Returns the result of left shifting o1 by o2, possibly in-place, or NULL /// on failure. /// /// This is the equivalent of the Python expression: o1 <<= o2. @@ -389,7 +431,8 @@ pub extern "C" fn pynumber_inplace_lshift( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceLshift" -///| Returns the result of right shifting o1 by o2, possibly in-place or NULL +///| +/// Returns the result of right shifting o1 by o2, possibly in-place or NULL /// on failure. /// /// This is the equivalent of the Python expression: o1 >>= o2. @@ -399,7 +442,8 @@ pub extern "C" fn pynumber_inplace_rshift( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceRshift" -///| Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL +///| +/// Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL /// on failure. /// /// This is the equivalent of the Python expression: o1 &= o2. @@ -409,7 +453,8 @@ pub extern "C" fn pynumber_inplace_and( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceAnd" -///| Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL +///| +/// Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL /// on failure. /// /// This is the equivalent of the Python expression: o1 ^= o2. @@ -419,7 +464,8 @@ pub extern "C" fn pynumber_inplace_xor( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceXor" -///| Returns the result of bitwise or of o1 and o2, possibly in-place, +///| +/// Returns the result of bitwise or of o1 and o2, possibly in-place, /// or NULL on failure. /// /// This is the equivalent of the Python expression: o1 |= o2. @@ -429,7 +475,8 @@ pub extern "C" fn pynumber_inplace_or( obj2 : PyObjectRef, ) -> PyObjectRef = "PyNumber_InPlaceOr" -///| Returns the integer n converted to a string with a base, with a base +///| +/// Returns the integer n converted to a string with a base, with a base /// marker of 0b, 0o or 0x prefixed if applicable. /// /// If n is not an int object, it is converted with PyNumber_Index first. */ @@ -439,18 +486,21 @@ pub extern "C" fn pynumber_to_base( base : Int, ) -> PyObjectRef = "PyNumber_ToBase" -///| Return 1 if the object provides sequence protocol, and zero +///| +/// Return 1 if the object provides sequence protocol, and zero /// otherwise. /// /// This function always succeeds. #owned(obj) pub extern "C" fn pysequence_check(obj : PyObjectRef) -> Int = "PySequence_Check" -///| Return the size of sequence object o, or -1 on failure. +///| +/// Return the size of sequence object o, or -1 on failure. #owned(obj) pub extern "C" fn pysequence_size(obj : PyObjectRef) -> Int = "PySequence_Size" -///| Return the concatenation of o1 and o2 on success, and NULL on failure. +///| +/// Return the concatenation of o1 and o2 on success, and NULL on failure. /// /// This is the equivalent of the Python expression: o1 + o2. */ #owned(obj1, obj2) @@ -459,7 +509,8 @@ pub extern "C" fn pysequence_concat( obj2 : PyObjectRef, ) -> PyObjectRef = "PySequence_Concat" -///| Return the result of repeating sequence object 'o' 'count' times, +///| +/// Return the result of repeating sequence object 'o' 'count' times, /// or NULL on failure. /// /// This is the equivalent of the Python expression: o * count. */ @@ -469,7 +520,8 @@ pub extern "C" fn pysequence_repeat( count : Int, ) -> PyObjectRef = "PySequence_Repeat" -///| Return the ith element of o, or NULL on failure. +///| +/// Return the ith element of o, or NULL on failure. /// /// This is the equivalent of the Python expression: o[i]. #owned(obj) @@ -478,7 +530,8 @@ pub extern "C" fn pysequence_get_item( idx : UInt64, ) -> PyObjectRef = "PySequence_GetItem" -///| Return the slice of sequence object o between i1 and i2, or NULL on failure. +///| +/// Return the slice of sequence object o between i1 and i2, or NULL on failure. /// /// This is the equivalent of the Python expression: o[i1:i2]. #owned(obj) @@ -488,7 +541,8 @@ pub extern "C" fn pysequence_get_slice( end : UInt64, ) -> PyObjectRef = "PySequence_GetSlice" -///| Assign object 'v' to the ith element of the sequence 'o'. Raise an exception +///| +/// Assign object 'v' to the ith element of the sequence 'o'. Raise an exception /// and return -1 on failure; return 0 on success. /// /// This is the equivalent of the Python statement o[i] = v. */ @@ -499,13 +553,15 @@ pub extern "C" fn pysequence_set_item( value : PyObjectRef, ) -> Int = "PySequence_SetItem" -///| Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure. +///| +/// Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure. /// /// This is the equivalent of the Python statement: del o[i]. */ #owned(obj) pub extern "C" fn pysequence_del_item(obj : PyObjectRef, idx : UInt64) -> Int = "PySequence_DelItem" -///| Assign the sequence object 'v' to the slice in sequence object 'o', +///| +/// Assign the sequence object 'v' to the slice in sequence object 'o', /// from 'i1' to 'i2'. Returns -1 on failure. /// /// This is the equivalent of the Python statement: o[i1:i2] = v. */ @@ -517,7 +573,8 @@ pub extern "C" fn pysequence_set_slice( new_list : PyObjectRef, ) -> Int = "PySequence_SetSlice" -///| Delete the slice in sequence object 'o' from 'i1' to 'i2'. +///| +/// Delete the slice in sequence object 'o' from 'i1' to 'i2'. /// Returns -1 on failure. /// /// This is the equivalent of the Python statement: del o[i1:i2]. */ @@ -528,18 +585,21 @@ pub extern "C" fn pysequence_del_slice( end : UInt64, ) -> Int = "PySequence_DelSlice" -///| Returns the sequence 'o' as a tuple on success, and NULL on failure. +///| +/// Returns the sequence 'o' as a tuple on success, and NULL on failure. /// /// This is equivalent to the Python expression: tuple(o). */ #owned(obj) pub extern "C" fn pysequence_tuple(obj : PyObjectRef) -> PyObjectRef = "PySequence_Tuple" -///| Returns the sequence 'o' as a list on success, and NULL on failure. +///| +/// Returns the sequence 'o' as a list on success, and NULL on failure. /// This is equivalent to the Python expression: list(o) */ #owned(obj) pub extern "C" fn pysequence_list(obj : PyObjectRef) -> PyObjectRef = "PySequence_List" -///| Return the sequence 'o' as a list, unless it's already a tuple or list. +///| +/// Return the sequence 'o' as a list, unless it's already a tuple or list. /// /// Use PySequence_Fast_GET_ITEM to access the members of this list, and /// PySequence_Fast_GET_SIZE to get its length. @@ -558,7 +618,8 @@ pub extern "C" fn pysequence_count( value : PyObjectRef, ) -> Int = "PySequence_Count" -///| Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence +///| +/// Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence /// 'seq'; -1 on error. /// /// Use __contains__ if possible, else _PySequence_IterSearch(). @@ -577,7 +638,8 @@ pub extern "C" fn pysequence_index( value : PyObjectRef, ) -> Int = "PySequence_Index" -///| Append sequence 'o2' to sequence 'o1', in-place when possible. Return the +///| +/// Append sequence 'o2' to sequence 'o1', in-place when possible. Return the /// resulting object, which could be 'o1', or NULL on failure. /// /// This is the equivalent of the Python expression: o1 += o2. */ @@ -587,7 +649,8 @@ pub extern "C" fn pysequence_inplace_concat( obj2 : PyObjectRef, ) -> PyObjectRef = "PySequence_InPlaceConcat" -///| Repeat sequence 'o' by 'count', in-place when possible. Return the resulting +///| +/// Repeat sequence 'o' by 'count', in-place when possible. Return the resulting /// object, which could be 'o', or NULL on failure. /// /// This is the equivalent of the Python expression: o1 *= count. */ @@ -597,18 +660,21 @@ pub extern "C" fn pysequence_inplace_repeat( count : Int, ) -> PyObjectRef = "PySequence_InPlaceRepeat" -///| Return 1 if the object provides mapping protocol, and 0 otherwise. +///| +/// Return 1 if the object provides mapping protocol, and 0 otherwise. /// /// This function always succeeds. #owned(obj) pub extern "C" fn pymapping_check(obj : PyObjectRef) -> Int = "PyMapping_Check" -///| Returns the number of keys in mapping object 'o' on success, and -1 on +///| +/// Returns the number of keys in mapping object 'o' on success, and -1 on /// failure. This is equivalent to the Python expression: len(o). */ #owned(obj) pub extern "C" fn pymapping_size(obj : PyObjectRef) -> Int = "PyMapping_Size" -///| On success, return 1 if the mapping object 'o' has the key 'key', +///| +/// On success, return 1 if the mapping object 'o' has the key 'key', /// and 0 otherwise. /// /// This is equivalent to the Python expression: key in o. @@ -620,7 +686,8 @@ pub extern "C" fn pymapping_has_key_string( key : CStr, ) -> Int = "PyMapping_HasKeyString" -///| Return 1 if the mapping object has the key 'key', and 0 otherwise. +///| +/// Return 1 if the mapping object has the key 'key', and 0 otherwise. /// /// This is equivalent to the Python expression: key in o. /// @@ -631,17 +698,20 @@ pub extern "C" fn pymapping_has_key( key : PyObjectRef, ) -> Int = "PyMapping_HasKey" -///| On success, return a list or tuple of the keys in mapping object 'o'. +///| +/// On success, return a list or tuple of the keys in mapping object 'o'. /// On failure, return NULL. */ #owned(obj) pub extern "C" fn pymapping_keys(obj : PyObjectRef) -> PyObjectRef = "PyMapping_Keys" -///| On success, return a list or tuple of the values in mapping object 'o'. +///| +/// On success, return a list or tuple of the values in mapping object 'o'. /// On failure, return NULL. #owned(obj) pub extern "C" fn pymapping_values(obj : PyObjectRef) -> PyObjectRef = "PyMapping_Values" -///| On success, return a list or tuple of the items in mapping object 'o', +///| +/// On success, return a list or tuple of the items in mapping object 'o', /// where each item is a tuple containing a key-value pair. On failure, return /// NULL. #owned(obj) @@ -676,13 +746,15 @@ pub extern "C" fn py_object_is_subclass( typeorclass : PyObjectRef, ) -> Int = "PyObject_IsSubclass" -///| PyObject repr to string +///| +/// PyObject repr to string pub fn py_object_moonbit_repr(obj : PyObjectRef) -> String { let repr = py_object_repr(obj) py_unicode_as_moonbit_string(repr) } -///| PyObject str to string +///| +/// PyObject str to string pub fn py_object_moonbit_str(obj : PyObjectRef) -> String { let str = py_object_str(obj) py_unicode_as_moonbit_string(str) diff --git a/cpython/cell.mbt b/cpython/cell.mbt index 4b75abc..ac90aec 100644 --- a/cpython/cell.mbt +++ b/cpython/cell.mbt @@ -20,4 +20,4 @@ pub extern "C" fn py_eval_eval_code( a : PyObjectRef, b : PyObjectRef, c : PyObjectRef, -) -> PyObjectRef = "PyEval_EvalCode" \ No newline at end of file +) -> PyObjectRef = "PyEval_EvalCode" diff --git a/cpython/ceval.mbt b/cpython/ceval.mbt index 73818e5..5b4622d 100644 --- a/cpython/ceval.mbt +++ b/cpython/ceval.mbt @@ -61,4 +61,4 @@ pub extern "C" fn py_eval_acquire_thread(tstate : PyThreadStateRef) = "PyEval_Ac ///| #owned(tstate) -pub extern "C" fn py_eval_release_thread(tstate : PyThreadStateRef) = "PyEval_ReleaseThread" \ No newline at end of file +pub extern "C" fn py_eval_release_thread(tstate : PyThreadStateRef) = "PyEval_ReleaseThread" diff --git a/cpython/class.mbt b/cpython/class.mbt index 1651d32..bff7789 100644 --- a/cpython/class.mbt +++ b/cpython/class.mbt @@ -24,4 +24,4 @@ pub extern "C" fn py_instance_method_new(a : PyObjectRef) -> PyObjectRef = "PyIn ///| #owned(a) -pub extern "C" fn py_instance_method_function(a : PyObjectRef) -> PyObjectRef = "PyInstanceMethod_Function" \ No newline at end of file +pub extern "C" fn py_instance_method_function(a : PyObjectRef) -> PyObjectRef = "PyInstanceMethod_Function" diff --git a/cpython/code.mbt b/cpython/code.mbt index db33590..480bb1c 100644 --- a/cpython/code.mbt +++ b/cpython/code.mbt @@ -51,4 +51,4 @@ pub extern "C" fn py_code_new_empty( ///| #owned(a) -pub extern "C" fn py_code_addr2_line(a : PyCodeObjectRef, b : Int) -> Int = "PyCode_Addr2Line" \ No newline at end of file +pub extern "C" fn py_code_addr2_line(a : PyCodeObjectRef, b : Int) -> Int = "PyCode_Addr2Line" diff --git a/cpython/codecs.mbt b/cpython/codecs.mbt index 831198e..677e3ca 100644 --- a/cpython/codecs.mbt +++ b/cpython/codecs.mbt @@ -101,4 +101,4 @@ pub extern "C" fn py_codec_backslash_replace_errors( #owned(exc) pub extern "C" fn py_codec_name_replace_errors( exc : PyObjectRef, -) -> PyObjectRef = "PyCodec_NameReplaceErrors" \ No newline at end of file +) -> PyObjectRef = "PyCodec_NameReplaceErrors" diff --git a/cpython/context.mbt b/cpython/context.mbt index efee81e..274f042 100644 --- a/cpython/context.mbt +++ b/cpython/context.mbt @@ -51,4 +51,4 @@ pub extern "C" fn py_context_var_reset( pub extern "C" fn _py_context_new_hamt_for_tests() -> PyObjectRef = "_PyContext_NewHamtForTests" ///| -pub extern "C" fn py_context_clear_free_list() -> Int = "PyContext_ClearFreeList" \ No newline at end of file +pub extern "C" fn py_context_clear_free_list() -> Int = "PyContext_ClearFreeList" diff --git a/dict.mbt b/dict.mbt index 50e4d35..6bba036 100644 --- a/dict.mbt +++ b/dict.mbt @@ -7,7 +7,8 @@ pub struct PyDict { priv obj : PyObject } -///| Create a python dict object. +///| +/// Create a python dict object. /// If the python object is not a dict, it will raise a TypeMisMatchError. pub fn PyDict::create(obj : PyObject) -> PyDict raise PyRuntimeError { guard obj.is_dict() else { raise TypeMisMatchError } @@ -19,7 +20,8 @@ fn PyDict::create_unchecked(obj : PyObject) -> PyDict { PyDict::{ obj, } } -///| Create a python dict object from a python object reference. +///| +/// Create a python dict object from a python object reference. /// If the python object is not a dict, it will raise a TypeMisMatchError. pub fn PyDict::create_by_ref( obj : @cpython.PyObjectRef, @@ -28,7 +30,8 @@ pub fn PyDict::create_by_ref( PyDict::{ obj: PyObject::create(obj) } } -///| Creates a new python dict object. +///| +/// Creates a new python dict object. /// /// ## Example /// @@ -53,7 +56,8 @@ pub fn PyDict::new() -> PyDict { PyDict::{ obj: PyObject::create(@cpython.py_dict_new()) } } -///| Return the length of the dict. +///| +/// Return the length of the dict. /// /// ## Example /// @@ -70,7 +74,8 @@ pub fn PyDict::len(self : PyDict) -> Int { @cpython.py_dict_size(self.obj_ref()).to_int() } -///| Return the elements of the dict by its key. +///| +/// Return the elements of the dict by its key. /// /// ## Example /// @@ -91,14 +96,16 @@ pub fn PyDict::get(self : PyDict, key : String) -> PyObjectEnum? { when(not(obj_ref.is_null()), fn() { PyObjectEnum::create_by_ref(obj_ref) }) } -///| Return the elements of the dict by its key, when the key is not string. +///| +/// Return the elements of the dict by its key, when the key is not string. pub fn PyDict::getByObj(self : PyDict, key : PyObject) -> PyObjectEnum? { let dict = self.obj_ref() let obj_ref = @cpython.py_dict_get_item(dict, key.obj_ref()) when(not(obj_ref.is_null()), fn() { PyObjectEnum::create_by_ref(obj_ref) }) } -///| Return the elements of the dict by its key. +///| +/// Return the elements of the dict by its key. /// /// **Note**: Will panic if the key is not found. /// @@ -119,7 +126,8 @@ pub fn PyDict::op_get(self : PyDict, key : String) -> PyObjectEnum { self.get(key).unwrap() } -///| Set the elements of the dict by its key (String). +///| +/// Set the elements of the dict by its key (String). /// /// ## Example /// @@ -152,7 +160,8 @@ pub fn[V : IsPyObject] PyDict::set( } -///| Set the elements of the dict by its key. (Object) +///| +/// Set the elements of the dict by its key. (Object) /// /// ## Example /// @@ -191,7 +200,8 @@ pub fn[K : IsPyObject, V : IsPyObject] PyDict::setByObj( } } -///| Set the elements of the dict by its key (String). +///| +/// Set the elements of the dict by its key (String). /// /// ## Example /// @@ -221,20 +231,23 @@ pub fn[V : IsPyObject] PyDict::op_set( self.set(key, val) } -///| Check if the dict contains the key. Note that the key is a string. +///| +/// Check if the dict contains the key. Note that the key is a string. /// If the key is not string, use `containsObj` instead. pub fn PyDict::contains(self : PyDict, key : String) -> Bool { let dict = self.obj_ref() @cpython.py_dict_contains(dict, PyString::from(key).obj_ref()) } -///| Check if the dict contains the key. +///| +/// Check if the dict contains the key. pub fn PyDict::containsObj(self : PyDict, key : PyObject) -> Bool { let dict = self.obj_ref() @cpython.py_dict_contains(dict, key.obj_ref()) } -///| Get the keys of the dict. +///| +/// Get the keys of the dict. /// /// **Notes**: It is slight different from the python dict.keys() method. /// In python, dict.keys() returns a view object that displays a list of all the keys. @@ -263,7 +276,8 @@ pub fn PyDict::keys(self : PyDict) -> PyList { PyList::create_by_ref_unchecked(@cpython.py_dict_keys(self.obj_ref())) } -///| Get the values of the dict. +///| +/// Get the values of the dict. /// /// **Notes**: It is slight different from the python dict.values() method. /// In python, dict.values() returns a view object that displays a list of all the values. @@ -292,7 +306,8 @@ pub fn PyDict::values(self : PyDict) -> PyList { PyList::create_by_ref_unchecked(@cpython.py_dict_values(self.obj_ref())) } -///| Get the items of the dict. +///| +/// Get the items of the dict. /// /// **Notes**: It is slight different from the python dict.items() method. /// In python, dict.items() returns a view object that displays a list of all the items. @@ -313,7 +328,8 @@ pub fn PyDict::items(self : PyDict) -> PyList { PyList::create_by_ref_unchecked(@cpython.py_dict_items(self.obj_ref())) } -///| Let python interpret print the dict directly. +///| +/// Let python interpret print the dict directly. /// /// **Note**: This is different from `println(dict)` and `dict.dump()`. /// although they always print the same content. diff --git a/float.mbt b/float.mbt index ba2e904..cd5be4f 100644 --- a/float.mbt +++ b/float.mbt @@ -3,7 +3,8 @@ pub struct PyFloat { priv obj : PyObject } -///| Create a python float object from a python object. +///| +/// Create a python float object from a python object. /// If the python object is not a float, it will raise a TypeMisMatchError. pub fn PyFloat::create(obj : PyObject) -> PyFloat raise PyRuntimeError { guard obj.is_float() else { raise TypeMisMatchError } @@ -15,7 +16,8 @@ fn PyFloat::create_unchecked(obj : PyObject) -> PyFloat { PyFloat::{ obj, } } -///| Ceate a python float object from a python object reference. +///| +/// Ceate a python float object from a python object reference. /// If the python object is not a float, it will raise a TypeMisMatchError. pub fn PyFloat::create_by_ref( obj : @cpython.PyObjectRef, @@ -34,7 +36,8 @@ test { ignore(PyFloat::create_by_ref_unchecked) } -///| Create a PyFloat from a Double value. +///| +/// Create a PyFloat from a Double value. /// /// ## Example /// @@ -46,7 +49,8 @@ pub fn PyFloat::from(value : Double) -> PyFloat { PyFloat::{ obj: @cpython.py_float_from_double(value) |> PyObject::create } } -///| Convert a PyFloat to a Double. +///| +/// Convert a PyFloat to a Double. /// /// ## Example /// @@ -58,7 +62,8 @@ pub fn PyFloat::to_double(self : PyFloat) -> Double { @cpython.py_float_as_double(self.obj_ref()) } -///| Print the PyFloat object direcly. +///| +/// Print the PyFloat object direcly. /// /// Different from use `println`, `dump` means we made python interpreter /// print the object directly. diff --git a/integer.mbt b/integer.mbt index b36be88..0a21712 100644 --- a/integer.mbt +++ b/integer.mbt @@ -7,7 +7,8 @@ pub struct PyInteger { priv obj : PyObject } -///| Create a python integer object from a python object. +///| +/// Create a python integer object from a python object. /// If pub fn PyInteger::create(obj : PyObject) -> PyInteger raise PyRuntimeError { guard obj.is_int() else { raise TypeMisMatchError } @@ -37,7 +38,8 @@ test { ignore(PyInteger::create_by_ref_unchecked) } -///| Create a PyInteger from an integer. +///| +/// Create a PyInteger from an integer. /// /// ## Example /// @@ -49,7 +51,8 @@ pub fn PyInteger::from(value : Int64) -> PyInteger { PyInteger::{ obj: PyObject::create(@cpython.py_long_from_long(value)) } } -///| Convert a PyInteger to an integer. +///| +/// Convert a PyInteger to an integer. /// /// ## Example /// @@ -61,7 +64,8 @@ pub fn PyInteger::to_int64(self : PyInteger) -> Int64 { @cpython.py_long_as_long(self.obj_ref()) } -///| Convert a PyInteger to a double. +///| +/// Convert a PyInteger to a double. /// /// ## Example /// @@ -73,7 +77,8 @@ pub fn PyInteger::to_double(self : PyInteger) -> Double { @cpython.py_long_as_double(self.obj_ref()) } -///| Print the PyInteger object direcly. +///| +/// Print the PyInteger object direcly. /// /// Different from use `println`, `dump` means we made python interpreter /// print the object directly. diff --git a/list.mbt b/list.mbt index 213dc1d..6972779 100644 --- a/list.mbt +++ b/list.mbt @@ -7,7 +7,8 @@ pub struct PyList { priv obj : PyObject } -///| Create an empty python list. +///| +/// Create an empty python list. /// /// ## Example /// @@ -20,7 +21,8 @@ pub fn PyList::new() -> PyList { PyList::{ obj: @cpython.py_list_new(0) |> PyObject::create } } -///| Create a python list object from a pyobject. +///| +/// Create a python list object from a pyobject. /// If the pyobject is not a list, it will raise a TypeMisMatchError. pub fn PyList::create(obj : PyObject) -> PyList raise PyRuntimeError { guard obj.is_list() else { raise TypeMisMatchError } @@ -32,7 +34,8 @@ fn PyList::create_unchecked(obj : PyObject) -> PyList { PyList::{ obj, } } -///| Create a python list object from a pyobject reference. +///| +/// Create a python list object from a pyobject reference. /// If the pyobject is not a list, it will raise a TypeMisMatchError. pub fn PyList::create_by_ref( obj : @cpython.PyObjectRef, @@ -46,7 +49,8 @@ fn PyList::create_by_ref_unchecked(obj : @cpython.PyObjectRef) -> PyList { PyList::{ obj: PyObject::create(obj) } } -///| Returns the length of the list. +///| +/// Returns the length of the list. /// /// ## Example /// @@ -73,7 +77,8 @@ pub fn PyList::len(self : PyList) -> Int { @cpython.py_list_size(self.obj_ref()).to_int() } -///| Append an item to the end of the list. +///| +/// Append an item to the end of the list. /// /// ## Example /// @@ -112,7 +117,8 @@ pub fn[T : IsPyObject] PyList::append(self : PyList, item : T) -> Unit { // let _ = @cpython.py_list_reverse(self.obj_ref()) //} -///| Create a new python list from a python object array +///| +/// Create a new python list from a python object array /// /// ## Example /// @@ -135,7 +141,8 @@ pub fn[T : IsPyObject] PyList::from(items : Array[T]) -> PyList { pylist } -///| Get the item at the specified index. +///| +/// Get the item at the specified index. /// /// **Notes**: Although python support negative index, the moonbit api does not /// support it. Code like `list.get(-1)` will return `None`. @@ -161,7 +168,8 @@ pub fn PyList::get(self : PyList, idx : Int) -> PyObjectEnum? { }) } -///| Get the item at the specified index. +///| +/// Get the item at the specified index. /// /// **Notes**: Although python support negative index, the moonbit api does not /// support it. which means code like `list[-1]` will be panic. @@ -182,7 +190,8 @@ pub fn PyList::op_get(self : PyList, idx : Int) -> PyObjectEnum { self.get(idx).unwrap() } -///| Set the item at the specified index. +///| +/// Set the item at the specified index. /// /// **Notes**: Although python support negative index, the moonbit api does not /// support it. which means code like `list.set(-1) = ...` will raise IndexOutOfBoundsError. @@ -213,7 +222,8 @@ pub fn[T : IsPyObject] PyList::set( } -///| Set the item at the specified index. +///| +/// Set the item at the specified index. /// /// **Notes**: Although python support negative index, the moonbit api does not /// support it. which means code like `list[-1] = ...` will be panic. @@ -240,7 +250,8 @@ pub fn[T : IsPyObject] PyList::op_set( } } -///| Let python interpreter print the list directly. +///| +/// Let python interpreter print the list directly. /// /// **Note**: It is different from `println(list)` and `list.dump()` /// although they always print the same content. diff --git a/main/main.mbt b/main/main.mbt index 265c8c8..76f1dd3 100644 --- a/main/main.mbt +++ b/main/main.mbt @@ -1,5 +1,5 @@ ///| -typealias @python.(PyInteger, PyList, PyTuple) +using @python {type PyInteger, type PyList, type PyTuple} ///| fn main { diff --git a/module.mbt b/module.mbt index ed8ba6b..2399944 100644 --- a/module.mbt +++ b/module.mbt @@ -41,7 +41,8 @@ test { } // REVIEW: what if user call pyimport twice or more? -///| Import a python module +///| +/// Import a python module /// /// ## Example /// @@ -50,7 +51,7 @@ test { /// /// assert_true(os is Some(_)) /// ``` -pub fn pyimport(name : String, print_err~ : Bool = false) -> PyModule? { +pub fn pyimport(name : String, print_err? : Bool = false) -> PyModule? { let obj = @cpython.py_import_import_module(name) if obj.is_null() { if print_err { @@ -64,7 +65,8 @@ pub fn pyimport(name : String, print_err~ : Bool = false) -> PyModule? { |> Some } -///| Get the name of the module. +///| +/// Get the name of the module. /// /// ## Example /// @@ -97,7 +99,8 @@ pub fn PyModule::dump(self : PyModule) -> Unit { self.obj.dump() } -///| Get attribute by name. +///| +/// Get attribute by name. /// /// ## Example /// @@ -131,7 +134,7 @@ pub fn PyModule::dump(self : PyModule) -> Unit { pub fn PyModule::get_attr( self : PyModule, attr : String, - print_err~ : Bool = false, + print_err? : Bool = false, ) -> PyObjectEnum? { if self.attrs.contains(attr) { return self.attrs.get(attr) diff --git a/obj.mbt b/obj.mbt index ba62b98..e61412c 100644 --- a/obj.mbt +++ b/obj.mbt @@ -109,7 +109,7 @@ pub fn PyObject::type_name(self : PyObject) -> String { pub fn PyObject::get_attr( self : PyObject, attr : String, - print_err~ : Bool = false, + print_err? : Bool = false, ) -> PyObjectEnum? { let f = @cpython.py_object_get_attr_string(self.obj_ref(), attr) if f.is_null() { diff --git a/str.mbt b/str.mbt index 39dd5ea..7ef5221 100644 --- a/str.mbt +++ b/str.mbt @@ -7,7 +7,8 @@ pub struct PyString { priv obj : PyObject } -///| Create a python string from a python object. +///| +/// Create a python string from a python object. /// If the python object is not a string, it will raise a TypeMisMatchError. pub fn PyString::create(obj : PyObject) -> PyString raise PyRuntimeError { guard obj.is_string() else { raise TypeMisMatchError } @@ -19,7 +20,8 @@ fn PyString::create_unchecked(obj : PyObject) -> PyString { PyString::{ obj, } } -///| Create a python string from a python object reference. +///| +/// Create a python string from a python object reference. ///If the python object is not a string, it will raise a TypeMisMatchError. pub fn PyString::create_by_ref( obj_ref : @cpython.PyObjectRef, @@ -40,7 +42,8 @@ test { ignore(PyString::create_by_ref_unchecked) } -///| Create a PyString from a string +///| +/// Create a PyString from a string /// /// ## Example /// @@ -54,7 +57,8 @@ pub fn PyString::from(s : String) -> PyString { } } -///| Print the PyString object direcly. +///| +/// Print the PyString object direcly. /// /// Different from use `println`, `dump` means we made python interpreter /// print the object directly. diff --git a/test/object_test.mbt b/test/object_test.mbt index 912be8f..b80b44f 100644 --- a/test/object_test.mbt +++ b/test/object_test.mbt @@ -1,13 +1,13 @@ ///| -typealias @python.( - PyInteger, - PyFloat, - PyString, - PyList, - PyTuple, - PyBool, - PyDict -) +using @python { + type PyInteger, + type PyFloat, + type PyString, + type PyList, + type PyTuple, + type PyBool, + type PyDict, +} ///| test "PyInteger Test" { diff --git a/time/lib.mbt b/time/lib.mbt index e3966dc..f25b7c1 100644 --- a/time/lib.mbt +++ b/time/lib.mbt @@ -1,5 +1,5 @@ ///| -typealias @python.(PyModule, PyTuple, PyFloat) +using @python {type PyModule, type PyTuple, type PyFloat} ///| pub struct TimeModule { @@ -44,7 +44,8 @@ pub fn sleep(seconds : Double) -> Unit { () } -///| Returns the time in seconds since the epoch as a floating-point number. +///| +/// Returns the time in seconds since the epoch as a floating-point number. /// Corresponds to `time.time()` in Python. pub fn time() -> Double { let lib = singleton() @@ -60,7 +61,8 @@ pub fn time() -> Double { t.to_double() } -///| Returns the time in nanoseconds since the epoch as an integer. +///| +/// Returns the time in nanoseconds since the epoch as an integer. /// Corresponds to `time.time_ns()` in Python. pub fn time_ns() -> Int64 { let lib = singleton() @@ -75,7 +77,8 @@ pub fn time_ns() -> Int64 { t.to_int64() } -///| Returns the value (in fractional seconds) of a monotonic clock. +///| +/// Returns the value (in fractional seconds) of a monotonic clock. /// Corresponds to `time.monotonic()` in Python. pub fn monotonic() -> Double { let lib = singleton() @@ -90,7 +93,8 @@ pub fn monotonic() -> Double { t.to_double() } -///| Returns the value (in nanoseconds) of a monotonic clock. +///| +/// Returns the value (in nanoseconds) of a monotonic clock. /// Corresponds to `time.monotonic_ns()` in Python. pub fn monotonic_ns() -> Int64 { let lib = singleton() @@ -105,7 +109,8 @@ pub fn monotonic_ns() -> Int64 { t.to_int64() } -///| Returns the value (in fractional seconds) of a performance counter. +///| +/// Returns the value (in fractional seconds) of a performance counter. /// Corresponds to `time.perf_counter()` in Python. pub fn perf_counter() -> Double { let lib = singleton() @@ -120,7 +125,8 @@ pub fn perf_counter() -> Double { t.to_double() } -///| Returns the value (in nanoseconds) of a performance counter. +///| +/// Returns the value (in nanoseconds) of a performance counter. /// Corresponds to `time.perf_counter_ns()` in Python. pub fn perf_counter_ns() -> Int64 { let lib = singleton() @@ -135,7 +141,8 @@ pub fn perf_counter_ns() -> Int64 { t.to_int64() } -///| Returns the value (in fractional seconds) of the sum of the system and user CPU time of the current process. +///| +/// Returns the value (in fractional seconds) of the sum of the system and user CPU time of the current process. /// Corresponds to `time.process_time()` in Python. pub fn process_time() -> Double { let lib = singleton() @@ -150,7 +157,8 @@ pub fn process_time() -> Double { t.to_double() } -///| Returns the value (in nanoseconds) of the sum of the system and user CPU time of the current process. +///| +/// Returns the value (in nanoseconds) of the sum of the system and user CPU time of the current process. /// Corresponds to `time.process_time_ns()` in Python. pub fn process_time_ns() -> Int64 { let lib = singleton() @@ -165,7 +173,8 @@ pub fn process_time_ns() -> Int64 { t.to_int64() } -///| Converts a time expressed in seconds since the epoch to a string representing local time. +///| +/// Converts a time expressed in seconds since the epoch to a string representing local time. /// If `secs_option` is `None`, the current time as returned by `time()` is used. /// Corresponds to `time.ctime([secs])` in Python. pub fn ctime(secs_option : Double?) -> String { diff --git a/tkinter/tkinter.mbt b/tkinter/tkinter.mbt index e573d1e..4c3a0b1 100644 --- a/tkinter/tkinter.mbt +++ b/tkinter/tkinter.mbt @@ -13,7 +13,13 @@ //} ///| -typealias @python.(PyModule, PyObject, PyTuple, PyDict, PyString) +using @python { + type PyModule, + type PyObject, + type PyTuple, + type PyDict, + type PyString, +} ///| pub suberror TkinterError { diff --git a/traits.mbt b/traits.mbt index f1b8257..46a23e8 100644 --- a/traits.mbt +++ b/traits.mbt @@ -10,7 +10,8 @@ impl IsPyObject with obj_ref(self) { self.obj().obj } -///| Return the type name of the object. +///| +/// Return the type name of the object. /// /// ## Example /// diff --git a/tuple.mbt b/tuple.mbt index 5847804..f9e250a 100644 --- a/tuple.mbt +++ b/tuple.mbt @@ -7,7 +7,8 @@ pub struct PyTuple { priv obj : PyObject } -///| Create a PyTuple object. +///| +/// Create a PyTuple object. /// /// **Notes**: Tuple type must know the size of the tuple. /// @@ -26,7 +27,8 @@ pub fn PyTuple::new(size : UInt64) -> PyTuple { PyTuple::{ obj: @cpython.pytuple_new(size) |> PyObject::create } } -///| Create a PyTuple object from a python object. +///| +/// Create a PyTuple object from a python object. /// If the python object is not a tuple, it will raise a TypeMisMatchError. pub fn PyTuple::create(obj : PyObject) -> PyTuple raise PyRuntimeError { guard obj.is_tuple() else { raise TypeMisMatchError } @@ -38,7 +40,8 @@ fn PyTuple::create_unchecked(obj : PyObject) -> PyTuple { PyTuple::{ obj, } } -///| Create a PyTuple object from a python object reference. +///| +/// Create a PyTuple object from a python object reference. /// If the python object is not a tuple, it will raise a TypeMisMatchError. pub fn PyTuple::create_by_ref( obj_ref : @cpython.PyObjectRef, @@ -57,7 +60,8 @@ test { ignore(PyTuple::create_by_ref_unchecked) } -///| Return the size of the tuple. +///| +/// Return the size of the tuple. /// /// ## Example: /// @@ -70,7 +74,8 @@ pub fn PyTuple::len(self : PyTuple) -> UInt64 { @cpython.pytuple_size(self.obj_ref()) } -///| Get the item at the given index. +///| +/// Get the item at the given index. /// /// **Notes**: Although python supports negative index, in moonbit, we don't have plan to /// support it. Code like `tuple.get(-1)` will return `None`. @@ -108,7 +113,8 @@ pub fn PyTuple::get(self : PyTuple, idx : Int) -> PyObjectEnum? { }) } -///| Get the item at the given index. +///| +/// Get the item at the given index. /// /// **Notes**: Although python supports negative index, in moonbit, we don't have plan to /// support it. Code like `tuple[-1]` will return `None`. @@ -130,7 +136,8 @@ pub fn PyTuple::op_get(self : PyTuple, idx : Int) -> PyObjectEnum { self.get(idx).unwrap() } -///| Set the item at the given index. +///| +/// Set the item at the given index. /// /// **Notes**: Although python supports negative index, in moonbit, we don't have plan to /// support it. Code like `tuple.set(-1, item)` will raise `IndexOutOfBoundError`. @@ -160,7 +167,8 @@ pub fn[T : IsPyObject] PyTuple::set( } -///| Set the item at the given index. +///| +/// Set the item at the given index. /// /// **Notes**: Although python supports negative index, in moonbit, we don't have plan to /// support it. Code like `tuple[-1] = item` will raise `IndexOutOfBoundError`. diff --git a/turtle/color.mbt b/turtle/color.mbt index 1ebc64e..39851d5 100644 --- a/turtle/color.mbt +++ b/turtle/color.mbt @@ -1,4 +1,5 @@ -///| Represents common colors used for drawing. +///| +/// Represents common colors used for drawing. /// Deriving Show provides a default to_string() which can be converted to lowercase for Python. pub(all) enum Color { Red @@ -21,7 +22,8 @@ pub(all) enum Color { Violet } derive(Show) -///| Converts the Color enum to a lowercase string representation suitable for Python turtle. +///| +/// Converts the Color enum to a lowercase string representation suitable for Python turtle. /// - self: The Color enum value. /// Returns: The color name as a PyString. pub fn Color::to_pystr(self : Color) -> PyString { diff --git a/turtle/lib.mbt b/turtle/lib.mbt index 4a1ec3f..d561b6f 100644 --- a/turtle/lib.mbt +++ b/turtle/lib.mbt @@ -1,14 +1,14 @@ ///| -typealias @python.( - PyModule, - PyObject, - PyTuple, - PyDict, - PyString, - PyInteger, - PyFloat, - PyCallable -) +using @python { + type PyModule, + type PyObject, + type PyTuple, + type PyDict, + type PyString, + type PyInteger, + type PyFloat, + type PyCallable, +} ///| pub suberror TurtleError { diff --git a/turtle/pen2.mbt b/turtle/pen2.mbt index 35a69f4..5ca9902 100644 --- a/turtle/pen2.mbt +++ b/turtle/pen2.mbt @@ -1,11 +1,13 @@ -///| Represents a turtle pen object, capable of drawing on the screen. +///| +/// Represents a turtle pen object, capable of drawing on the screen. /// corresponds to `turtle.Pen` or the default turtle instance in Python. pub struct Pen { priv pen : PyObject methods : Map[String, PyCallable] // Caches method lookups } -///| Retrieves a callable Python method from the cached methods or the underlying Python object. +///| +/// Retrieves a callable Python method from the cached methods or the underlying Python object. /// - name: The name of the method. /// Returns Some(PyCallable) if the method is found, None otherwise. fn Pen::get_method(self : Pen, name : String) -> PyCallable? { @@ -22,7 +24,8 @@ fn Pen::get_method(self : Pen, name : String) -> PyCallable? { } } -///| Creates a new turtle pen instance. +///| +/// Creates a new turtle pen instance. /// In Python, this might correspond to `turtle.Pen()` or obtaining the default instance. /// This Moonbit function creates a new `turtle.Pen()` instance. pub fn Pen::new() -> Pen { @@ -32,7 +35,8 @@ pub fn Pen::new() -> Pen { Pen::{ pen, methods: Map::new() } } -///| Moves the pen to the home position (0,0) and sets heading to 0 degrees. +///| +/// Moves the pen to the home position (0,0) and sets heading to 0 degrees. /// corresponds to `pen.home()` in Python. pub fn Pen::home(self : Pen) -> Unit { guard self.get_method("home") is Some(func) else { @@ -43,7 +47,8 @@ pub fn Pen::home(self : Pen) -> Unit { () } -///| Sets the pen size (thickness). +///| +/// Sets the pen size (thickness). /// - size: The pen thickness. Must be positive. /// corresponds to `pen.pensize(size)` in Python. pub fn Pen::pensize(self : Pen, size : Double) -> Unit { @@ -61,7 +66,8 @@ pub fn Pen::pensize(self : Pen, size : Double) -> Unit { } -///| Returns the current x-coordinate of the pen. +///| +/// Returns the current x-coordinate of the pen. /// corresponds to `pen.xcor()` in Python. pub fn Pen::xcor(self : Pen) -> Double { guard self.get_method("xcor") is Some(func) else { @@ -73,7 +79,8 @@ pub fn Pen::xcor(self : Pen) -> Double { x.to_double() } -///| Returns the current y-coordinate of the pen. +///| +/// Returns the current y-coordinate of the pen. /// corresponds to `pen.ycor()` in Python. pub fn Pen::ycor(self : Pen) -> Double { guard self.get_method("ycor") is Some(func) else { @@ -85,7 +92,8 @@ pub fn Pen::ycor(self : Pen) -> Double { y.to_double() } -///| Returns the current position as a tuple of (x, y) coordinates. +///| +/// Returns the current position as a tuple of (x, y) coordinates. /// corresponds to `pen.position()` or `pen.pos()` in Python. pub fn Pen::position(self : Pen) -> (Double, Double) { guard self.get_method("position") is Some(func) else { @@ -114,7 +122,8 @@ pub fn Pen::position(self : Pen) -> (Double, Double) { (x_py.to_double(), y_py.to_double()) } -///| Returns the current heading of the pen in degrees. +///| +/// Returns the current heading of the pen in degrees. /// corresponds to `pen.heading()` in Python. pub fn Pen::heading(self : Pen) -> Double { guard self.get_method("heading") is Some(func) else { @@ -129,7 +138,8 @@ pub fn Pen::heading(self : Pen) -> Double { h.to_double() } -///| Returns the current unit for angles set by the `degrees()` or `radians()` methods. +///| +/// Returns the current unit for angles set by the `degrees()` or `radians()` methods. /// Note: This method name might be slightly misleading in Python's turtle documentation. /// corresponds to `pen.radians()` in Python (when radians are used). /// If using degrees, you might check `turtle.degrees()` which is usually global. @@ -147,7 +157,8 @@ pub fn Pen::radians(self : Pen) -> Double { r.to_double() } -///| Sets the pen speed. +///| +/// Sets the pen speed. /// - speed: An enum representing the desired drawing speed. /// corresponds to `pen.speed(speed)` in Python, where speed is an integer. pub fn Pen::speed(self : Pen, speed : Speed) -> Unit { @@ -161,7 +172,8 @@ pub fn Pen::speed(self : Pen, speed : Speed) -> Unit { } -///| Sets the pen color. +///| +/// Sets the pen color. /// - color: The pen color. /// corresponds to `pen.pencolor(color)` in Python. pub fn Pen::pencolor(self : Pen, color : Color) -> Unit { @@ -175,7 +187,8 @@ pub fn Pen::pencolor(self : Pen, color : Color) -> Unit { } -///| Sets the pen width. +///| +/// Sets the pen width. /// - width: The pen width. Must be positive. /// corresponds to `pen.width(width)` in Python. pub fn Pen::width(self : Pen, width : Double) -> Unit { @@ -193,7 +206,8 @@ pub fn Pen::width(self : Pen, width : Double) -> Unit { } -///| Moves the pen forward by the specified distance. +///| +/// Moves the pen forward by the specified distance. /// - distance: The distance to move forward. Must be positive. /// corresponds to `pen.forward(distance)` or `pen.fd(distance)` in Python. pub fn Pen::forward(self : Pen, distance : Double) -> Unit { @@ -211,7 +225,8 @@ pub fn Pen::forward(self : Pen, distance : Double) -> Unit { } -///| Moves the pen backward by the specified distance. +///| +/// Moves the pen backward by the specified distance. /// - distance: The distance to move backward. Must be positive. /// corresponds to `pen.backward(distance)` or `pen.bk(distance)` or `pen.ba(distance)` in Python. pub fn Pen::backward(self : Pen, distance : Double) -> Unit { @@ -230,7 +245,8 @@ pub fn Pen::backward(self : Pen, distance : Double) -> Unit { } -///| Turns the pen left by the specified angle. +///| +/// Turns the pen left by the specified angle. /// - angle: The angle in degrees to turn left. /// corresponds to `pen.left(angle)` or `pen.lt(angle)` in Python. pub fn Pen::left(self : Pen, angle : Double) -> Unit { @@ -244,7 +260,8 @@ pub fn Pen::left(self : Pen, angle : Double) -> Unit { } -///| Turns the pen right by the specified angle. +///| +/// Turns the pen right by the specified angle. /// - angle: The angle in degrees to turn right. /// corresponds to `pen.right(angle)` or `pen.rt(angle)` in Python. pub fn Pen::right(self : Pen, angle : Double) -> Unit { @@ -258,7 +275,8 @@ pub fn Pen::right(self : Pen, angle : Double) -> Unit { } -///| Moves the pen to an absolute position (x, y). +///| +/// Moves the pen to an absolute position (x, y). /// - x: The target x-coordinate. /// - y: The target y-coordinate. /// corresponds to `pen.goto(x, y)` or `pen.setpos(x, y)` or `pen.setposition(x, y)` in Python. @@ -273,7 +291,8 @@ pub fn Pen::goto(self : Pen, x : Double, y : Double) -> Unit { } -///| Makes the turtle invisible. +///| +/// Makes the turtle invisible. /// corresponds to `pen.hideturtle()` or `pen.ht()` in Python. pub fn Pen::hide(self : Pen) -> Unit { guard self.get_method("hideturtle") is Some(func) else { @@ -284,7 +303,8 @@ pub fn Pen::hide(self : Pen) -> Unit { } -///| Lifts the pen up. No drawing will occur when the pen moves. +///| +/// Lifts the pen up. No drawing will occur when the pen moves. /// corresponds to `pen.penup()` or `pen.pu()` or `pen.up()` in Python. pub fn Pen::penup(self : Pen) -> Unit { guard self.get_method("penup") is Some(func) else { @@ -295,7 +315,8 @@ pub fn Pen::penup(self : Pen) -> Unit { } -///| Puts the pen down. Drawing will occur when the pen moves. +///| +/// Puts the pen down. Drawing will occur when the pen moves. /// corresponds to `pen.pendown()` or `pen.pd()` or `pen.down()` in Python. pub fn Pen::pendown(self : Pen) -> Unit { guard self.get_method("pendown") is Some(func) else { @@ -306,7 +327,8 @@ pub fn Pen::pendown(self : Pen) -> Unit { } -///| Draws a dot at the current position. +///| +/// Draws a dot at the current position. /// - size: The diameter of the dot. Must be positive. /// - color: The color of the dot. /// corresponds to `pen.dot(size, color)` in Python. @@ -329,7 +351,8 @@ pub fn Pen::dot(self : Pen, size : Double, color : Color) -> Unit { // Simpler way to ignore return value } -///| Deletes the pen's drawings from the screen, but does not move the pen. +///| +/// Deletes the pen's drawings from the screen, but does not move the pen. /// corresponds to `pen.clear()` in Python. pub fn Pen::clear(self : Pen) -> Unit { guard self.get_method("clear") is Some(func) else { @@ -342,7 +365,8 @@ pub fn Pen::clear(self : Pen) -> Unit { // Add more Pen methods -///| Sets the fill color. +///| +/// Sets the fill color. /// - color: The color used for filling. /// corresponds to `pen.fillcolor(color)` in Python. pub fn Pen::fillcolor(self : Pen, color : Color) -> Unit { @@ -356,7 +380,8 @@ pub fn Pen::fillcolor(self : Pen, color : Color) -> Unit { } -///| Sets the pen color and fill color. +///| +/// Sets the pen color and fill color. /// - color: The color used for pen and fill. /// corresponds to `pen.color(color)` in Python. Can also take two colors, but we simplify here. pub fn Pen::color(self : Pen, color : Color) -> Unit { @@ -370,7 +395,8 @@ pub fn Pen::color(self : Pen, color : Color) -> Unit { } -///| Returns True if the pen is down, False otherwise. +///| +/// Returns True if the pen is down, False otherwise. /// corresponds to `pen.isdown()` in Python. pub fn Pen::isdown(self : Pen) -> Bool { guard self.get_method("isdown") is Some(func) else { @@ -382,7 +408,8 @@ pub fn Pen::isdown(self : Pen) -> Bool { b.to_bool() } -///| Makes the turtle visible. +///| +/// Makes the turtle visible. /// corresponds to `pen.showturtle()` or `pen.st()` in Python. pub fn Pen::show(self : Pen) -> Unit { guard self.get_method("showturtle") is Some(func) else { @@ -393,7 +420,8 @@ pub fn Pen::show(self : Pen) -> Unit { } -///| Returns True if the turtle is visible, False otherwise. +///| +/// Returns True if the turtle is visible, False otherwise. /// corresponds to `pen.isvisible()` in Python. pub fn Pen::isvisible(self : Pen) -> Bool { guard self.get_method("isvisible") is Some(func) else { @@ -405,7 +433,8 @@ pub fn Pen::isvisible(self : Pen) -> Bool { b.to_bool() } -///| Starts color filling. +///| +/// Starts color filling. /// corresponds to `pen.begin_fill()` in Python. pub fn Pen::begin_fill(self : Pen) -> Unit { guard self.get_method("begin_fill") is Some(func) else { @@ -416,7 +445,8 @@ pub fn Pen::begin_fill(self : Pen) -> Unit { } -///| Stops color filling and fills the area bounded by the last begin_fill() and this call. +///| +/// Stops color filling and fills the area bounded by the last begin_fill() and this call. /// corresponds to `pen.end_fill()` in Python. pub fn Pen::end_fill(self : Pen) -> Unit { guard self.get_method("end_fill") is Some(func) else { @@ -427,7 +457,8 @@ pub fn Pen::end_fill(self : Pen) -> Unit { } -///| Draws a circle. +///| +/// Draws a circle. /// - radius: The radius of the circle. A positive radius means counterclockwise, negative means clockwise. /// - extent: Optional. An angle in degrees. If given, only part of the circle is drawn. /// - steps: Optional. An integer. The number of steps to use for approximating the circle. @@ -435,8 +466,8 @@ pub fn Pen::end_fill(self : Pen) -> Unit { pub fn Pen::circle( self : Pen, radius : Double, - extent~ : Double? = None, - steps~ : Int? = None, + extent? : Double? = None, + steps? : Int? = None, ) -> Unit { guard self.get_method("circle") is Some(func) else { println("Failed to get Pen::circle method") @@ -457,7 +488,8 @@ pub fn Pen::circle( } -///| Leaves a copy of the turtle shape at the current location. +///| +/// Leaves a copy of the turtle shape at the current location. /// Returns a stamp_id which can be used later with clearstamp() or clearstamps(). /// corresponds to `pen.stamp()` in Python. /// Note: The return value (stamp_id) is an integer in Python, we return it as Int. @@ -474,7 +506,8 @@ pub fn Pen::stamp(self : Pen) -> Int { i.to_int64().to_int() // Convert to Int } -///| Deletes the stamp with the given stampid. +///| +/// Deletes the stamp with the given stampid. /// - stamp_id: The id of the stamp to delete, as returned by stamp(). /// corresponds to `pen.clearstamp(stampid)` in Python. pub fn Pen::clearstamp(self : Pen, stamp_id : Int) -> Unit { @@ -488,10 +521,11 @@ pub fn Pen::clearstamp(self : Pen, stamp_id : Int) -> Unit { } -///| Deletes all or the first/last n stamps. +///| +/// Deletes all or the first/last n stamps. /// - n: Optional. If None, delete all stamps. If n > 0, delete the first n stamps. If n < 0, delete the last abs(n) stamps. /// corresponds to `pen.clearstamps(n=None)` in Python. -pub fn Pen::clearstamps(self : Pen, n~ : Int? = None) -> Unit { +pub fn Pen::clearstamps(self : Pen, n? : Int? = None) -> Unit { guard self.get_method("clearstamps") is Some(func) else { println("Failed to get Pen::clearstamps method") return @@ -509,7 +543,8 @@ pub fn Pen::clearstamps(self : Pen, n~ : Int? = None) -> Unit { } -///| Resets the pen's and screen's state. Deletes drawings, recenters pen, resets variables. +///| +/// Resets the pen's and screen's state. Deletes drawings, recenters pen, resets variables. /// corresponds to `pen.reset()` in Python. pub fn Pen::reset(self : Pen) -> Unit { guard self.get_method("reset") is Some(func) else { @@ -520,7 +555,8 @@ pub fn Pen::reset(self : Pen) -> Unit { } -///| Sets the turtle shape. +///| +/// Sets the turtle shape. /// - name: The name of the shape. Use the Shape enum for common shapes. /// corresponds to `pen.shape(name)` in Python. pub fn Pen::shape(self : Pen, name : Shape) -> Unit { @@ -534,16 +570,17 @@ pub fn Pen::shape(self : Pen, name : Shape) -> Unit { } -///| Sets the shape's stretches and outline. +///| +/// Sets the shape's stretches and outline. /// - stretch_width: Stretchfactor for width, perpendicular to orientation. /// - stretch_len: Stretchfactor for length, in direction of orientation. /// - outline: Optional outline thickness. /// corresponds to `pen.shapesize(stretch_wid=None, stretch_len=None, outline=None)` in Python. pub fn Pen::shapesize( self : Pen, - stretch_width~ : Double? = None, - stretch_len~ : Double? = None, - outline~ : Int? = None, + stretch_width? : Double? = None, + stretch_len? : Double? = None, + outline? : Int? = None, ) -> Unit { guard self.get_method("shapesize") is Some(func) else { println("Failed to get Pen::shapesize method") diff --git a/turtle/shape.mbt b/turtle/shape.mbt index 893773a..b596a67 100644 --- a/turtle/shape.mbt +++ b/turtle/shape.mbt @@ -1,4 +1,5 @@ -///| Represents common shapes for the turtle cursor. +///| +/// Represents common shapes for the turtle cursor. /// Deriving Show provides a default to_string() which can be converted to lowercase for Python. pub(all) enum Shape { Arrow diff --git a/utils.mbt b/utils.mbt index 364c711..5bfb7d7 100644 --- a/utils.mbt +++ b/utils.mbt @@ -32,7 +32,8 @@ fn init { init_py() } -///| elimnate the quotes from a string +///| +/// elimnate the quotes from a string /// /// ## Example /// From 80b3282aa66149da8feafc913fc53eacd9ef9bae Mon Sep 17 00:00:00 2001 From: Haoxiang Fei Date: Sat, 8 Nov 2025 13:59:15 +0800 Subject: [PATCH 2/2] chore: update interfaces --- cpython/pkg.generated.mbti | 633 +++++++++++++++++++++++++++++++++++++ main/pkg.generated.mbti | 13 + pkg.generated.mbti | 214 +++++++++++++ test/pkg.generated.mbti | 13 + time/pkg.generated.mbti | 39 +++ tkinter/pkg.generated.mbti | 33 ++ turtle/pkg.generated.mbti | 116 +++++++ 7 files changed, 1061 insertions(+) create mode 100644 cpython/pkg.generated.mbti create mode 100644 main/pkg.generated.mbti create mode 100644 pkg.generated.mbti create mode 100644 test/pkg.generated.mbti create mode 100644 time/pkg.generated.mbti create mode 100644 tkinter/pkg.generated.mbti create mode 100644 turtle/pkg.generated.mbti diff --git a/cpython/pkg.generated.mbti b/cpython/pkg.generated.mbti new file mode 100644 index 0000000..290c4b8 --- /dev/null +++ b/cpython/pkg.generated.mbti @@ -0,0 +1,633 @@ +// Generated using `moon info`, DON'T EDIT IT +package "Kaida-Amethyst/python/cpython" + +// Values +fn __py_callable_check(PyObjectRef) -> Int + +fn __py_dict_contains(PyObjectRef, PyObjectRef) -> Int + +fn _py_context_new_hamt_for_tests() -> PyObjectRef + +fn print_pyobject(PyObjectRef) -> Unit + +fn py_bool_check(PyObjectRef) -> Bool + +fn py_bool_from_long(Int64) -> PyObjectRef + +fn py_call_iter_new(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_callable_check(PyObjectRef) -> Bool + +fn py_cell_get(PyObjectRef) -> PyObjectRef + +fn py_cell_new(PyObjectRef) -> PyObjectRef + +fn py_cell_set(PyObjectRef, PyObjectRef) -> Int + +fn py_class_method_new(PyObjectRef) -> PyObjectRef + +fn py_code_addr2_line(PyCodeObjectRef, Int) -> Int + +fn py_code_new(Int, Int, Int, Int, Int, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, Int, PyObjectRef) -> PyCodeObjectRef + +fn py_code_new_empty(CStr, CStr, Int) -> PyCodeObjectRef + +fn py_code_new_with_pos_only_args(Int, Int, Int, Int, Int, Int, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, Int, PyObjectRef) -> PyCodeObjectRef + +fn py_codec_backslash_replace_errors(PyObjectRef) -> PyObjectRef + +fn py_codec_decode(PyObjectRef, CStr, CStr) -> PyObjectRef + +fn py_codec_decoder(CStr) -> PyObjectRef + +fn py_codec_encode(PyObjectRef, CStr, CStr) -> PyObjectRef + +fn py_codec_encoder(CStr) -> PyObjectRef + +fn py_codec_ignore_errors(PyObjectRef) -> PyObjectRef + +fn py_codec_incremental_decoder(CStr, CStr) -> PyObjectRef + +fn py_codec_incremental_encoder(CStr, CStr) -> PyObjectRef + +fn py_codec_known_encoding(CStr) -> Int + +fn py_codec_lookup_error(CStr) -> PyObjectRef + +fn py_codec_name_replace_errors(PyObjectRef) -> PyObjectRef + +fn py_codec_register(PyObjectRef) -> Int + +fn py_codec_register_error(CStr, PyObjectRef) -> Int + +fn py_codec_replace_errors(PyObjectRef) -> PyObjectRef + +fn py_codec_stream_reader(CStr, PyObjectRef, CStr) -> PyObjectRef + +fn py_codec_stream_writer(CStr, PyObjectRef, CStr) -> PyObjectRef + +fn py_codec_strict_errors(PyObjectRef) -> PyObjectRef + +fn py_codec_xml_char_ref_replace_errors(PyObjectRef) -> PyObjectRef + +fn py_complex_from_doubles(Double, Double) -> PyObjectRef + +fn py_complex_imag_as_double(PyObjectRef) -> Double + +fn py_complex_real_as_double(PyObjectRef) -> Double + +fn py_context_clear_free_list() -> Int + +fn py_context_copy(PyObjectRef) -> PyObjectRef + +fn py_context_copy_current() -> PyObjectRef + +fn py_context_enter(PyObjectRef) -> Int + +fn py_context_exit(PyObjectRef) -> Int + +fn py_context_new() -> PyObjectRef + +fn py_context_var_get(PyObjectRef, PyObjectRef, ArrayPyObjectRef) -> Int + +fn py_context_var_new(CStr, PyObjectRef) -> PyObjectRef + +fn py_context_var_reset(PyObjectRef, PyObjectRef) -> Int + +fn py_context_var_set(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_decref(PyObjectRef) -> Unit + +fn py_dict_check(PyObjectRef) -> Bool + +fn py_dict_clear(PyObjectRef) -> Unit + +fn py_dict_contains(PyObjectRef, PyObjectRef) -> Bool + +fn py_dict_copy(PyObjectRef) -> PyObjectRef + +fn py_dict_del_item(PyObjectRef, PyObjectRef) -> Int + +fn py_dict_del_item_string(PyObjectRef, String) -> Int + +fn py_dict_get_item(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_dict_get_item_string(PyObjectRef, String) -> PyObjectRef + +fn py_dict_items(PyObjectRef) -> PyObjectRef + +fn py_dict_keys(PyObjectRef) -> PyObjectRef + +fn py_dict_merge(PyObjectRef, PyObjectRef, Int) -> Int + +fn py_dict_merge_from_seq2(PyObjectRef, PyObjectRef, Int) -> Int + +fn py_dict_new() -> PyObjectRef + +fn py_dict_set_item(PyObjectRef, PyObjectRef, PyObjectRef) -> Int + +fn py_dict_set_item_string(PyObjectRef, String, PyObjectRef) -> Int + +fn py_dict_size(PyObjectRef) -> UInt64 + +fn py_dict_update(PyObjectRef, PyObjectRef) -> Int + +fn py_dict_values(PyObjectRef) -> PyObjectRef + +fn py_err_clear() -> Unit + +fn py_err_occurred() -> PyObjectRef + +fn py_err_print() -> Unit + +fn py_eval_acquire_thread(PyThreadStateRef) -> Unit + +fn py_eval_call_object_with_keywords(PyObjectRef, PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_eval_eval_code(PyObjectRef, PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_eval_get_builtins() -> PyObjectRef + +fn py_eval_get_func_desc(PyObjectRef) -> CStr + +fn py_eval_get_func_name(PyObjectRef) -> CStr + +fn py_eval_get_globals() -> PyObjectRef + +fn py_eval_get_locals() -> PyObjectRef + +fn py_eval_init_threads() -> Unit + +fn py_eval_release_thread(PyThreadStateRef) -> Unit + +fn py_eval_restore_thread(PyThreadStateRef) -> Unit + +fn py_eval_save_thread() -> PyThreadStateRef + +fn py_eval_threads_initialized() -> Int + +fn py_file_from_fd(Int, CStr, CStr, Int, CStr, CStr, CStr, Int) -> PyObjectRef + +fn py_file_get_line(PyObjectRef, Int) -> PyObjectRef + +fn py_file_new_std_printer(Int) -> PyObjectRef + +fn py_file_open_code(CStr) -> PyObjectRef + +fn py_file_open_code_object(PyObjectRef) -> PyObjectRef + +fn py_file_write_object(PyObjectRef, PyObjectRef, Int) -> Int + +fn py_file_write_string(CStr, PyObjectRef) -> Int + +fn py_finalize() -> Unit + +fn py_float_as_double(PyObjectRef) -> Double + +fn py_float_check(PyObjectRef) -> Bool + +fn py_float_from_double(Double) -> PyObjectRef + +fn py_float_from_string(PyObjectRef) -> PyObjectRef + +fn py_float_get_info() -> PyObjectRef + +fn py_float_get_max() -> Double + +fn py_float_get_min() -> Double + +fn py_frozen_set_new(PyObjectRef) -> PyObjectRef + +fn py_function_check(PyObjectRef) -> Bool + +fn py_function_get_annotations(PyObjectRef) -> PyObjectRef + +fn py_function_get_closure(PyObjectRef) -> PyObjectRef + +fn py_function_get_code(PyObjectRef) -> PyObjectRef + +fn py_function_get_defaults(PyObjectRef) -> PyObjectRef + +fn py_function_get_globals(PyObjectRef) -> PyObjectRef + +fn py_function_get_kw_defaults(PyObjectRef) -> PyObjectRef + +fn py_function_get_module(PyObjectRef) -> PyObjectRef + +fn py_function_new(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_function_new_with_qual_name(PyObjectRef, PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_function_set_annotations(PyObjectRef, PyObjectRef) -> Int + +fn py_function_set_closure(PyObjectRef, PyObjectRef) -> Int + +fn py_function_set_defaults(PyObjectRef, PyObjectRef) -> Int + +fn py_function_set_kw_defaults(PyObjectRef, PyObjectRef) -> Int + +fn py_get_recursion_limit() -> Int + +fn py_import_add_module(CStr) -> PyObjectRef + +fn py_import_add_module_object(PyObjectRef) -> PyObjectRef + +fn py_import_cleanup() -> Unit + +fn py_import_exec_code_module(CStr, PyObjectRef) -> PyObjectRef + +fn py_import_exec_code_module_ex(CStr, PyObjectRef, CStr) -> PyObjectRef + +fn py_import_exec_code_module_object(PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_import_exec_code_module_with_pathnames(CStr, PyObjectRef, CStr, CStr) -> PyObjectRef + +fn py_import_get_importer(PyObjectRef) -> PyObjectRef + +fn py_import_get_magic_number() -> Int + +fn py_import_get_magic_tag() -> CStr + +fn py_import_get_module(PyObjectRef) -> PyObjectRef + +fn py_import_get_module_dict() -> PyObjectRef + +fn py_import_import(PyObjectRef) -> PyObjectRef + +fn py_import_import_frozen_module(CStr) -> Int + +fn py_import_import_frozen_module_object(PyObjectRef) -> Int + +fn py_import_import_module(String) -> PyObjectRef + +fn py_import_import_module_level(CStr, PyObjectRef, PyObjectRef, PyObjectRef, Int) -> PyObjectRef + +fn py_import_import_module_level_object(PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef, Int) -> PyObjectRef + +fn py_import_import_module_no_block(CStr) -> PyObjectRef + +fn py_import_reload_module(PyObjectRef) -> PyObjectRef + +fn py_incref(PyObjectRef) -> Unit + +fn py_init() -> Unit + +fn py_instance_method_function(PyObjectRef) -> PyObjectRef + +fn py_instance_method_new(PyObjectRef) -> PyObjectRef + +fn py_int_check(PyObjectRef) -> Bool + +fn py_is_initialized() -> Bool + +fn py_list_append(PyObjectRef, PyObjectRef) -> Int + +fn py_list_as_tuple(PyObjectRef) -> PyObjectRef + +fn py_list_check(PyObjectRef) -> Bool + +fn py_list_get_item(PyObjectRef, Int64) -> PyObjectRef + +fn py_list_get_slice(PyObjectRef, Int64, Int64) -> PyObjectRef + +fn py_list_insert(PyObjectRef, Int64, PyObjectRef) -> Int + +fn py_list_new(Int64) -> PyObjectRef + +fn py_list_reverse(PyObjectRef) -> Int + +fn py_list_set_item(PyObjectRef, Int64, PyObjectRef) -> Int + +fn py_list_set_slice(PyObjectRef, Int64, Int64, PyObjectRef) -> Int + +fn py_list_size(PyObjectRef) -> Int64 + +fn py_list_sort(PyObjectRef) -> Int + +fn py_long_as_double(PyObjectRef) -> Double + +fn py_long_as_long(PyObjectRef) -> Int64 + +fn py_long_from_long(Int64) -> PyObjectRef + +fn py_make_pending_calls() -> Int + +fn py_method_clear_free_list() -> Int + +fn py_method_function(PyObjectRef) -> PyObjectRef + +fn py_method_new(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_method_self(PyObjectRef) -> PyObjectRef + +fn py_module_check(PyObjectRef) -> Bool + +fn py_module_get_dict(PyObjectRef) -> PyObjectRef + +fn py_module_get_filename_object(PyObjectRef) -> PyObjectRef + +fn py_module_get_name(PyObjectRef) -> CStr + +fn py_module_get_name_object(PyObjectRef) -> PyObjectRef + +fn py_module_new(CStr) -> PyObjectRef + +fn py_module_new_object(PyObjectRef) -> PyObjectRef + +fn py_none_check(PyObjectRef) -> Bool + +fn py_object_as_file_descriptor(PyObjectRef) -> Int + +fn py_object_ascii(PyObjectRef) -> PyObjectRef + +fn py_object_bytes(PyObjectRef) -> PyObjectRef + +fn py_object_call(PyObjectRef, PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_object_call_object(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_object_clear_weak_refs(PyObjectRef) -> Unit + +fn py_object_del_item(PyObjectRef, PyObjectRef) -> Int + +fn py_object_del_item_string(PyObjectRef, CStr) -> Int + +fn py_object_dir(PyObjectRef) -> PyObjectRef + +fn py_object_generic_get_attr(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_object_generic_set_attr(PyObjectRef, PyObjectRef, PyObjectRef) -> Int + +fn py_object_get_attr(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_object_get_attr_string(PyObjectRef, String) -> PyObjectRef + +fn py_object_get_item(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn py_object_get_iter(PyObjectRef) -> PyObjectRef + +fn py_object_has_attr(PyObjectRef, PyObjectRef) -> Int + +fn py_object_has_attr_string(PyObjectRef, String) -> Int + +fn py_object_is_instance(PyObjectRef, PyObjectRef) -> Int + +fn py_object_is_subclass(PyObjectRef, PyObjectRef) -> Int + +fn py_object_is_true(PyObjectRef) -> Bool + +fn py_object_moonbit_repr(PyObjectRef) -> String + +fn py_object_moonbit_str(PyObjectRef) -> String + +fn py_object_not(PyObjectRef) -> Int + +fn py_object_repr(PyObjectRef) -> PyObjectRef + +fn py_object_rich_compare(PyObjectRef, PyObjectRef, Int) -> PyObjectRef + +fn py_object_rich_compare_bool(PyObjectRef, PyObjectRef, Int) -> Int + +fn py_object_self_iter(PyObjectRef) -> PyObjectRef + +fn py_object_set_attr(PyObjectRef, PyObjectRef, PyObjectRef) -> Int + +fn py_object_set_attr_string(PyObjectRef, String, PyObjectRef) -> Int + +fn py_object_set_item(PyObjectRef, PyObjectRef, PyObjectRef) -> Int + +fn py_object_size(PyObjectRef) -> UInt64 + +fn py_object_str(PyObjectRef) -> PyObjectRef + +fn py_object_type(PyObjectRef) -> PyObjectRef + +fn py_odict_del_item(PyObjectRef, PyObjectRef) -> Int + +fn py_odict_new() -> PyObjectRef + +fn py_odict_set_item(PyObjectRef, PyObjectRef, PyObjectRef) -> Int + +fn py_repr_enter(PyObjectRef) -> Int + +fn py_repr_leave(PyObjectRef) -> Unit + +fn py_seq_iter_new(PyObjectRef) -> PyObjectRef + +fn py_set_add(PyObjectRef, PyObjectRef) -> Int + +fn py_set_check(PyObjectRef) -> Bool + +fn py_set_clear(PyObjectRef) -> Int + +fn py_set_contains(PyObjectRef, PyObjectRef) -> Int + +fn py_set_discard(PyObjectRef, PyObjectRef) -> Int + +fn py_set_new(PyObjectRef) -> PyObjectRef + +fn py_set_pop(PyObjectRef) -> PyObjectRef + +fn py_set_recursion_limit(Int) -> Unit + +fn py_set_size(PyObjectRef) -> Int64 + +fn py_static_method_new(PyObjectRef) -> PyObjectRef + +fn py_string_check(PyObjectRef) -> Bool + +fn py_tuple_check(PyObjectRef) -> Bool + +fn py_type(PyObjectRef) -> PyTypeObjectRef + +fn py_type_name(PyTypeObjectRef) -> String + +fn py_unicode_as_moonbit_string(PyObjectRef) -> String + +fn py_unicode_as_utf16_string(PyObjectRef) -> PyObjectRef + +fn py_unicode_as_utf8(PyObjectRef) -> String + +fn py_unicode_from_moonbit_string(String) -> PyObjectRef + +fn py_unicode_from_string(String) -> PyObjectRef + +fn py_unicode_from_string_and_size(CStr, UInt64) -> PyObjectRef + +fn py_unicode_from_unicode(CWStr, UInt64) -> PyObjectRef + +fn pyindex_check(PyObjectRef) -> Int + +fn pyiter_check(PyObjectRef) -> Int + +fn pyiter_next(PyObjectRef) -> PyObjectRef + +fn pymapping_check(PyObjectRef) -> Int + +fn pymapping_get_item_string(PyObjectRef, CStr) -> PyObjectRef + +fn pymapping_has_key(PyObjectRef, PyObjectRef) -> Int + +fn pymapping_has_key_string(PyObjectRef, CStr) -> Int + +fn pymapping_items(PyObjectRef) -> PyObjectRef + +fn pymapping_keys(PyObjectRef) -> PyObjectRef + +fn pymapping_set_item_string(PyObjectRef, CStr, PyObjectRef) -> Int + +fn pymapping_size(PyObjectRef) -> Int + +fn pymapping_values(PyObjectRef) -> PyObjectRef + +fn pynumber_absolute(PyObjectRef) -> PyObjectRef + +fn pynumber_add(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_and(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_as_ssize_t(PyObjectRef, PyObjectRef) -> Int + +fn pynumber_check(PyObjectRef) -> Int + +fn pynumber_divmod(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_float(PyObjectRef) -> PyObjectRef + +fn pynumber_floor_divide(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_index(PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_add(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_and(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_floor_divide(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_lshift(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_multiply(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_or(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_power(PyObjectRef, PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_remainder(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_rshift(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_subtract(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_true_divide(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_inplace_xor(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_invert(PyObjectRef) -> PyObjectRef + +fn pynumber_long(PyObjectRef) -> PyObjectRef + +fn pynumber_lshift(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_multiply(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_negative(PyObjectRef) -> PyObjectRef + +fn pynumber_or(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_positive(PyObjectRef) -> PyObjectRef + +fn pynumber_power(PyObjectRef, PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_remainder(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_rshift(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_subtract(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_to_base(PyObjectRef, Int) -> PyObjectRef + +fn pynumber_true_divide(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pynumber_xor(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pyobkect_format(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pysequence_check(PyObjectRef) -> Int + +fn pysequence_concat(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pysequence_contains(PyObjectRef, PyObjectRef) -> Int + +fn pysequence_count(PyObjectRef, PyObjectRef) -> Int + +fn pysequence_del_item(PyObjectRef, UInt64) -> Int + +fn pysequence_del_slice(PyObjectRef, UInt64, UInt64) -> Int + +fn pysequence_fast(PyObjectRef, CStr) -> PyObjectRef + +fn pysequence_get_item(PyObjectRef, UInt64) -> PyObjectRef + +fn pysequence_get_slice(PyObjectRef, UInt64, UInt64) -> PyObjectRef + +fn pysequence_index(PyObjectRef, PyObjectRef) -> Int + +fn pysequence_inplace_concat(PyObjectRef, PyObjectRef) -> PyObjectRef + +fn pysequence_inplace_repeat(PyObjectRef, Int) -> PyObjectRef + +fn pysequence_list(PyObjectRef) -> PyObjectRef + +fn pysequence_repeat(PyObjectRef, Int) -> PyObjectRef + +fn pysequence_set_item(PyObjectRef, UInt64, PyObjectRef) -> Int + +fn pysequence_set_slice(PyObjectRef, UInt64, UInt64, PyObjectRef) -> Int + +fn pysequence_size(PyObjectRef) -> Int + +fn pysequence_tuple(PyObjectRef) -> PyObjectRef + +fn pytuple_get_item(PyObjectRef, UInt64) -> PyObjectRef + +fn pytuple_get_slice(PyObjectRef, UInt64, UInt64) -> PyObjectRef + +fn pytuple_new(UInt64) -> PyObjectRef + +fn pytuple_set_item(PyObjectRef, UInt64, PyObjectRef) -> Int + +fn pytuple_size(PyObjectRef) -> UInt64 + +// Errors + +// Types and methods +type ArrayPyObjectRef + +type CStr + +type CWStr + +type PyCodeObjectRef + +type PyObjectRef +fn PyObjectRef::dump(Self) -> Unit +fn PyObjectRef::is_bool(Self) -> Bool +fn PyObjectRef::is_callable(Self) -> Bool +fn PyObjectRef::is_dict(Self) -> Bool +fn PyObjectRef::is_float(Self) -> Bool +fn PyObjectRef::is_function(Self) -> Bool +fn PyObjectRef::is_int(Self) -> Bool +fn PyObjectRef::is_list(Self) -> Bool +fn PyObjectRef::is_module(Self) -> Bool +fn PyObjectRef::is_null(Self) -> Bool +fn PyObjectRef::is_set(Self) -> Bool +fn PyObjectRef::is_string(Self) -> Bool + +type PyThreadStateRef + +type PyTypeObjectRef + +// Type aliases + +// Traits + diff --git a/main/pkg.generated.mbti b/main/pkg.generated.mbti new file mode 100644 index 0000000..56682a9 --- /dev/null +++ b/main/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "Kaida-Amethyst/python/main" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits + diff --git a/pkg.generated.mbti b/pkg.generated.mbti new file mode 100644 index 0000000..9f42e20 --- /dev/null +++ b/pkg.generated.mbti @@ -0,0 +1,214 @@ +// Generated using `moon info`, DON'T EDIT IT +package "Kaida-Amethyst/python" + +import( + "Kaida-Amethyst/python/cpython" +) + +// Values +fn init_py() -> Unit + +fn pyimport(String, print_err? : Bool) -> PyModule? + +fn strip_quot(String) -> String + +// Errors +pub suberror PyRuntimeError { + TypeMisMatchError + IndexOutOfBoundsError + KeyIsUnHashableError + InVokeError +} +impl Show for PyRuntimeError + +// Types and methods +pub struct PyBool { + // private fields +} +fn PyBool::create(PyObject) -> Self raise PyRuntimeError +fn PyBool::create_by_ref(@cpython.PyObjectRef) -> Self raise PyRuntimeError +fn PyBool::dump(Self) -> Unit +fn PyBool::from(Bool) -> Self +fn PyBool::is_false(Self) -> Bool +fn PyBool::is_true(Self) -> Bool +fn PyBool::not(Self) -> Self +fn PyBool::to_bool(Self) -> Bool +impl IsPyObject for PyBool +impl Show for PyBool + +pub struct PyCallable { + // private fields +} +fn PyCallable::create(PyObject) -> Self raise PyRuntimeError +fn PyCallable::create_by_ref(@cpython.PyObjectRef) -> Self raise PyRuntimeError +fn PyCallable::dump(Self) -> Unit +fn PyCallable::invoke(Self, args? : PyTuple, kwargs? : PyDict, print_err? : Bool) -> PyObjectEnum? raise PyRuntimeError +impl IsPyObject for PyCallable +impl Show for PyCallable + +pub struct PyDict { + // private fields +} +fn PyDict::contains(Self, String) -> Bool +fn PyDict::containsObj(Self, PyObject) -> Bool +fn PyDict::create(PyObject) -> Self raise PyRuntimeError +fn PyDict::create_by_ref(@cpython.PyObjectRef) -> Self raise PyRuntimeError +fn PyDict::drop(Self) -> Unit +fn PyDict::dump(Self) -> Unit +fn PyDict::get(Self, String) -> PyObjectEnum? +fn PyDict::getByObj(Self, PyObject) -> PyObjectEnum? +fn PyDict::items(Self) -> PyList +fn PyDict::keys(Self) -> PyList +fn PyDict::len(Self) -> Int +fn PyDict::new() -> Self +fn PyDict::op_get(Self, String) -> PyObjectEnum +fn[V : IsPyObject] PyDict::op_set(Self, String, V) -> Unit +fn[V : IsPyObject] PyDict::set(Self, String, V) -> Unit +fn[K : IsPyObject, V : IsPyObject] PyDict::setByObj(Self, K, V) -> Unit raise PyRuntimeError +fn PyDict::values(Self) -> PyList +impl IsPyObject for PyDict +impl Show for PyDict + +pub struct PyFloat { + // private fields +} +fn PyFloat::create(PyObject) -> Self raise PyRuntimeError +fn PyFloat::create_by_ref(@cpython.PyObjectRef) -> Self raise PyRuntimeError +fn PyFloat::drop(Self) -> Unit +fn PyFloat::dump(Self) -> Unit +fn PyFloat::from(Double) -> Self +fn PyFloat::to_double(Self) -> Double +impl IsPyObject for PyFloat +impl Show for PyFloat + +pub struct PyInteger { + // private fields +} +fn PyInteger::create(PyObject) -> Self raise PyRuntimeError +fn PyInteger::create_by_ref(@cpython.PyObjectRef) -> Self raise PyRuntimeError +fn PyInteger::create_unchecked(PyObject) -> Self +fn PyInteger::drop(Self) -> Unit +fn PyInteger::dump(Self) -> Unit +fn PyInteger::from(Int64) -> Self +fn PyInteger::to_double(Self) -> Double +fn PyInteger::to_int64(Self) -> Int64 +impl IsPyObject for PyInteger +impl Show for PyInteger + +pub struct PyList { + // private fields +} +fn[T : IsPyObject] PyList::append(Self, T) -> Unit +fn PyList::create(PyObject) -> Self raise PyRuntimeError +fn PyList::create_by_ref(@cpython.PyObjectRef) -> Self raise PyRuntimeError +fn PyList::drop(Self) -> Unit +fn PyList::dump(Self) -> Unit +fn[T : IsPyObject] PyList::from(Array[T]) -> Self +fn PyList::get(Self, Int) -> PyObjectEnum? +fn PyList::len(Self) -> Int +fn PyList::new() -> Self +fn PyList::op_get(Self, Int) -> PyObjectEnum +fn[T : IsPyObject] PyList::op_set(Self, Int, T) -> Unit +fn[T : IsPyObject] PyList::set(Self, Int, T) -> Unit raise PyRuntimeError +impl IsPyObject for PyList +impl Show for PyList + +pub struct PyModule { + // private fields +} +fn PyModule::create(PyObject) -> Self raise PyRuntimeError +fn PyModule::create_by_ref(@cpython.PyObjectRef) -> Self raise PyRuntimeError +fn PyModule::dump(Self) -> Unit +fn PyModule::get_attr(Self, String, print_err? : Bool) -> PyObjectEnum? +fn PyModule::get_name(Self) -> String +impl IsPyObject for PyModule +impl Show for PyModule + +pub struct PyObject { + // private fields +} +fn PyObject::create(@cpython.PyObjectRef) -> Self +fn PyObject::drop(Self) -> Unit +fn PyObject::dump(Self) -> Unit +fn PyObject::get_attr(Self, String, print_err? : Bool) -> PyObjectEnum? +fn PyObject::is_bool(Self) -> Bool +fn PyObject::is_callable(Self) -> Bool +fn PyObject::is_dict(Self) -> Bool +fn PyObject::is_float(Self) -> Bool +fn PyObject::is_int(Self) -> Bool +fn PyObject::is_list(Self) -> Bool +fn PyObject::is_module(Self) -> Bool +fn PyObject::is_null(Self) -> Bool +fn PyObject::is_string(Self) -> Bool +fn PyObject::is_tuple(Self) -> Bool +fn PyObject::type_name(Self) -> String +fn PyObject::type_of(Self) -> PyType +impl IsPyObject for PyObject +impl Show for PyObject + +pub(all) enum PyObjectEnum { + PyInteger(PyInteger) + PyFloat(PyFloat) + PyBool(PyBool) + PyString(PyString) + PyTuple(PyTuple) + PyList(PyList) + PyDict(PyDict) + PyModule(PyModule) + PyCallable(PyCallable) + PyClass(PyObject) +} +fn PyObjectEnum::create(PyObject) -> Self +fn PyObjectEnum::create_by_ref(@cpython.PyObjectRef) -> Self +fn PyObjectEnum::dump(Self) -> Unit +impl Show for PyObjectEnum + +pub struct PyString { + // private fields +} +fn PyString::create(PyObject) -> Self raise PyRuntimeError +fn PyString::create_by_ref(@cpython.PyObjectRef) -> Self raise PyRuntimeError +fn PyString::drop(Self) -> Unit +fn PyString::dump(Self) -> Unit +fn PyString::from(String) -> Self +impl IsPyObject for PyString +impl Show for PyString + +pub struct PyTuple { + // private fields +} +fn PyTuple::create(PyObject) -> Self raise PyRuntimeError +fn PyTuple::create_by_ref(@cpython.PyObjectRef) -> Self raise PyRuntimeError +fn PyTuple::drop(Self) -> Unit +fn PyTuple::dump(Self) -> Unit +fn PyTuple::get(Self, Int) -> PyObjectEnum? +fn PyTuple::len(Self) -> UInt64 +fn PyTuple::new(UInt64) -> Self +fn PyTuple::op_get(Self, Int) -> PyObjectEnum +fn[T : IsPyObject] PyTuple::op_set(Self, Int, T) -> Unit +fn[T : IsPyObject] PyTuple::set(Self, Int, T) -> Unit +impl IsPyObject for PyTuple +impl Show for PyTuple + +pub enum PyType { + PyInteger + PyFloat + PyBool + PyString + PyTuple + PyList + PyDict + PyModule + PyCallable + PyClass +} + +// Type aliases + +// Traits +pub trait IsPyObject { + obj(Self) -> PyObject + obj_ref(Self) -> @cpython.PyObjectRef + type_name(Self) -> String +} + diff --git a/test/pkg.generated.mbti b/test/pkg.generated.mbti new file mode 100644 index 0000000..7d3e998 --- /dev/null +++ b/test/pkg.generated.mbti @@ -0,0 +1,13 @@ +// Generated using `moon info`, DON'T EDIT IT +package "Kaida-Amethyst/python/test" + +// Values + +// Errors + +// Types and methods + +// Type aliases + +// Traits + diff --git a/time/pkg.generated.mbti b/time/pkg.generated.mbti new file mode 100644 index 0000000..3655ba2 --- /dev/null +++ b/time/pkg.generated.mbti @@ -0,0 +1,39 @@ +// Generated using `moon info`, DON'T EDIT IT +package "Kaida-Amethyst/python/time" + +// Values +fn ctime(Double?) -> String + +fn monotonic() -> Double + +fn monotonic_ns() -> Int64 + +fn perf_counter() -> Double + +fn perf_counter_ns() -> Int64 + +fn process_time() -> Double + +fn process_time_ns() -> Int64 + +fn sleep(Double) -> Unit + +fn time() -> Double + +fn time_ns() -> Int64 + +// Errors +pub suberror TurtleError { + LoadTimeModuleError +} +impl Show for TurtleError + +// Types and methods +pub struct TimeModule { + // private fields +} + +// Type aliases + +// Traits + diff --git a/tkinter/pkg.generated.mbti b/tkinter/pkg.generated.mbti new file mode 100644 index 0000000..3ca13ff --- /dev/null +++ b/tkinter/pkg.generated.mbti @@ -0,0 +1,33 @@ +// Generated using `moon info`, DON'T EDIT IT +package "Kaida-Amethyst/python/tkinter" + +// Values + +// Errors +pub suberror TkinterError { + LoadTkinterError +} +impl Show for TkinterError + +// Types and methods +pub struct Label { + // private fields +} +fn Label::new(Window, String) -> Self +fn Label::pack(Self) -> Unit + +pub struct Tkinter { + // private fields +} + +pub struct Window { + // private fields +} +fn Window::mainloop(Self) -> Unit +fn Window::new() -> Self +fn Window::set_title(Self, String) -> Unit + +// Type aliases + +// Traits + diff --git a/turtle/pkg.generated.mbti b/turtle/pkg.generated.mbti new file mode 100644 index 0000000..c5211c4 --- /dev/null +++ b/turtle/pkg.generated.mbti @@ -0,0 +1,116 @@ +// Generated using `moon info`, DON'T EDIT IT +package "Kaida-Amethyst/python/turtle" + +import( + "Kaida-Amethyst/python" +) + +// Values +fn bgcolor(Color) -> Unit + +// Errors +pub suberror TurtleError { + LoadTurtleError +} +impl Show for TurtleError + +// Types and methods +pub(all) enum Color { + Red + Green + Blue + Purple + Orange + Yellow + Black + Silver + White + Gray + Brown + Cyan + Magenta + Lime + Pink + Teal + Indigo + Violet +} +fn Color::to_pystr(Self) -> @python.PyString +impl Show for Color + +pub struct Pen { + methods : Map[String, @python.PyCallable] + // private fields +} +fn Pen::backward(Self, Double) -> Unit +fn Pen::begin_fill(Self) -> Unit +fn Pen::circle(Self, Double, extent? : Double?, steps? : Int?) -> Unit +fn Pen::clear(Self) -> Unit +fn Pen::clearstamp(Self, Int) -> Unit +fn Pen::clearstamps(Self, n? : Int?) -> Unit +fn Pen::color(Self, Color) -> Unit +fn Pen::dot(Self, Double, Color) -> Unit +fn Pen::end_fill(Self) -> Unit +fn Pen::fillcolor(Self, Color) -> Unit +fn Pen::forward(Self, Double) -> Unit +fn Pen::goto(Self, Double, Double) -> Unit +fn Pen::heading(Self) -> Double +fn Pen::hide(Self) -> Unit +fn Pen::home(Self) -> Unit +fn Pen::isdown(Self) -> Bool +fn Pen::isvisible(Self) -> Bool +fn Pen::left(Self, Double) -> Unit +fn Pen::new() -> Self +fn Pen::pencolor(Self, Color) -> Unit +fn Pen::pendown(Self) -> Unit +fn Pen::pensize(Self, Double) -> Unit +fn Pen::penup(Self) -> Unit +fn Pen::position(Self) -> (Double, Double) +fn Pen::radians(Self) -> Double +fn Pen::reset(Self) -> Unit +fn Pen::right(Self, Double) -> Unit +fn Pen::shape(Self, Shape) -> Unit +fn Pen::shapesize(Self, stretch_width? : Double?, stretch_len? : Double?, outline? : Int?) -> Unit +fn Pen::show(Self) -> Unit +fn Pen::speed(Self, Speed) -> Unit +fn Pen::stamp(Self) -> Int +fn Pen::width(Self, Double) -> Unit +fn Pen::xcor(Self) -> Double +fn Pen::ycor(Self) -> Double + +pub struct Screen { + // private fields +} +fn Screen::bgcolor(Self, Color) -> Unit +fn Screen::new() -> Self +fn Screen::setup(Self, Double, Double) -> Unit +fn Screen::title(Self, String) -> Unit +fn Screen::tracer(Self, Int) -> Unit +fn Screen::update(Self) -> Unit + +pub(all) enum Shape { + Arrow + Turtle + Circle + Square + Triangle + Classic +} +impl Show for Shape + +pub(all) enum Speed { + Fastest + Fast + Normal + Slow + Slowest +} + +pub struct Turtle { + // private fields +} + +// Type aliases + +// Traits +