@@ -3,7 +3,7 @@ const pyjlcallbacktype = pynew()
33
44pyjlcallback_repr (self) = Py (" <jl $(repr (self)) >" )
55
6- pyjlcallback_str (self) = Py (string ( self))
6+ pyjlcallback_str (self) = Py (sprint (print, self))
77
88function pyjlcallback_call (self, args_:: Py , kwargs_:: Py )
99 if pylen (kwargs_) > 0
@@ -44,18 +44,73 @@ function init_jlwrap_callback()
4444end
4545
4646pyjlcallback (f) = pyjl (pyjlcallbacktype, f)
47- export pyjlcallback
4847
49- function pycallback (f; name= nothing , doc= nothing )
50- f2 = pyjlcallback (f)
48+ """
49+ pyfunc(f; [name], [doc])
50+
51+ Wrap the callable `f` as an ordinary Python function.
52+
53+ Its name and docstring can be given with `name` and `doc`.
54+
55+ Unlike `Py(f)` (or `pyjl(f)`), the arguments passed to `f` are always of type `Py`, i.e.
56+ they are never converted.
57+ """
58+ function pyfunc (f; name= nothing , doc= nothing )
59+ f2 = ispy (f) ? f : pyjlcallback (f)
5160 f3 = pywrapcallback (f2)
5261 pydel! (f2)
5362 if name != = nothing
5463 f3. __name__ = f3. __qualname__ = name
64+ else
65+ f3. __name__ = f3. __qualname__ = " <lambda>"
5566 end
5667 if doc != = nothing
5768 f3. __doc__ = doc
5869 end
5970 return f3
6071end
61- export pycallback
72+ export pyfunc
73+
74+ """
75+ pyclassmethod(f)
76+
77+ Convert callable `f` to a Python class method.
78+
79+ If `f` is not a Python object (e.g. if `f` is a `Function`) then it is converted to one with
80+ [`pyfunc`](@ref). In particular this means the arguments passed to `f` are always of type
81+ `Py`.
82+ """
83+ pyclassmethod (f) = pybuiltins. classmethod (ispy (f) ? f : pyfunc (f))
84+ export pyclassmethod
85+
86+ """
87+ pystaticmethod(f)
88+
89+ Convert callable `f` to a Python static method.
90+
91+ If `f` is not a Python object (e.g. if `f` is a `Function`) then it is converted to one with
92+ [`pyfunc`](@ref). In particular this means the arguments passed to `f` are always of type
93+ `Py`.
94+ """
95+ pystaticmethod (f) = pybuiltins. staticmethod (ispy (f) ? f : pyfunc (f))
96+ export pystaticmethod
97+
98+ """
99+ pyproperty(; get=nothing, set=nothing, del=nothing, doc=nothing)
100+ pyproperty(get)
101+
102+ Create a Python `property` with the given getter, setter and deleter.
103+
104+ If `get`, `set` or `del` is not a Python object (e.g. if it is a `Function`) then it is
105+ converted to one with [`pyfunc`](@ref). In particular this means the arguments passed to it
106+ are always of type `Py`.
107+ """
108+ pyproperty (; get= nothing , set= nothing , del= nothing , doc= nothing ) =
109+ pybuiltins. property (
110+ fget = ispy (get) || get === nothing ? get : pyfunc (get),
111+ fset = ispy (set) || set === nothing ? set : pyfunc (set),
112+ fdel = ispy (del) || del === nothing ? del : pyfunc (del),
113+ doc = doc,
114+ )
115+ pyproperty (get) = pyproperty (get= get)
116+ export pyproperty
0 commit comments