class
Crython::PyObject
- Crython::PyObject
- Reference
- Object
Overview
Extension methods for PyObject
Included Modules
- Crython::ObjectProtocol
Defined in:
crython/py2cr/basic.crcrython/py2cr/collections.cr
crython/pyobject.cr
Constructors
Macro Summary
-
method_missing(call)
Convenience syntax for simple Python method calls.
Instance Method Summary
- #!=(other : PyObject) : PyObject
-
#!=(other) : PyObject
Returns
trueif this object is not equal to other. - #%(other : PyObject) : PyObject
- #%(other) : PyObject
- #*(other : PyObject) : PyObject
- #*(other) : PyObject
- #**(other : PyObject) : PyObject
- #**(other) : PyObject
- #+(other : PyObject) : PyObject
- #+(other) : PyObject
- #-(other : PyObject) : PyObject
- #-(other) : PyObject
- #/(other : PyObject) : PyObject
- #/(other) : PyObject
- #//(other : PyObject) : PyObject
- #//(other) : PyObject
- #<(other : PyObject) : PyObject
- #<(other) : PyObject
- #<=(other : PyObject) : PyObject
- #<=(other) : PyObject
- #==(other : PyObject) : PyObject
-
#==(other) : PyObject
Returns
false(other can only be aValuehere). - #>(other : PyObject) : PyObject
- #>(other) : PyObject
- #>=(other : PyObject) : PyObject
- #>=(other) : PyObject
- #[](*key) : PyObject
- #[]=(key, value) : Nil
-
#call(call : String | Symbol, *args, **kwargs) : PyObject
Reliable public API for Python attribute lookup and invocation.
- #call?(call : String | Symbol, *args, **kwargs) : PyObject | Nil
- #finalize
-
#get_type_name : String
Helper method to get Python object type name
- #inspect(io) : Nil
-
#need_decref : Bool
Ownership rules -
need_decref = truemeans this wrapper owns one Python reference. -
#need_decref=(need_decref : Bool)
Ownership rules -
need_decref = truemeans this wrapper owns one Python reference. -
#raw : Pointer(Void)
Access the raw Python object pointer
-
#to_a(element_type : T.class) : Array(T) forall T
Convert to Crystal Array
-
#to_b : Bool
Convert to Crystal Bool
-
#to_complex : Complex
Convert Python complex to Crystal Complex
-
#to_cr
Convert to appropriate Crystal type
-
#to_dict : Hash(PyObject, PyObject)
Convert Python dict to Crystal Hash(PyObject, PyObject)
-
#to_f64 : Float64
Convert to Crystal Float64
-
#to_h(key_type : K.class, value_type : V.class) : Hash(K, V) forall K, V
Convert to Crystal Hash
-
#to_i32 : Int32
Convert to Crystal Int32
-
#to_i64 : Int64
Convert to Crystal Int64
-
#to_list : Array(PyObject)
Convert Python list to Crystal Array(PyObject)
- #to_py : PyObject
-
#to_s(io : IO) : Nil
Convert to Crystal String
- #to_s(io) : Nil
-
#to_tuple : Array(PyObject)
Convert Python tuple to Crystal Array(PyObject)
Instance methods inherited from module Crython::ObjectProtocol
<=>(other : ObjectProtocol)
<=>,
attr(attr : String) : PyObject
attr,
attr?(attr : String) : PyObject | Nil
attr?,
callable? : Bool
callable?,
del_attr(attr : String) : Bool
del_attr,
has_attr?(attr : String) : Bool
has_attr?,
set_attr(attr : String, obj : ObjectMethods)
set_attr,
to_unsafe
to_unsafe
Constructor Detail
Macro Detail
Convenience syntax for simple Python method calls.
For uppercase attribute names or other complex call sites, prefer
obj.call("Name", ...) because Crystal method syntax is stricter
than Python attribute syntax.
Instance Method Detail
Returns true if this object is not equal to other.
By default this method is implemented as !(self == other)
so there's no need to override this unless there's a more efficient
way to do it.
Returns false (other can only be a Value here).
Reliable public API for Python attribute lookup and invocation.
Use this when the Python attribute name is not a natural Crystal
method name, such as class constructors like Counter.
Ownership rules
need_decref = truemeans this wrapper owns one Python reference.need_decref = falsemeans borrowed/non-owning wrapper.- When passing values to a stealing API (e.g. PyTuple_SetItem, PyList_SetItem), transfer ownership only if we own the ref; otherwise incref before passing.
- When passing values to a non-stealing API (e.g. PyDict_SetItem), decref temporary values only if this wrapper owns them.
Ownership rules
need_decref = truemeans this wrapper owns one Python reference.need_decref = falsemeans borrowed/non-owning wrapper.- When passing values to a stealing API (e.g. PyTuple_SetItem, PyList_SetItem), transfer ownership only if we own the ref; otherwise incref before passing.
- When passing values to a non-stealing API (e.g. PyDict_SetItem), decref temporary values only if this wrapper owns them.
Convert Python dict to Crystal Hash(PyObject, PyObject)
Convert to Crystal Hash