libpython-clj2.python.class

Namespace to help create a new python class from Clojure. Used as a core implementation technique for bridging JVM objects into python.

create-class

(create-class name bases cls-hashmap)

Create a new class object. Any callable values in the cls-hashmap will be presented as instance methods. Things in the cls hashmap had better be either atoms or already converted python objects. You may get surprised otherwise; you have been warned. See the classes-test file in test/libpython-clj.

Calling super.init() may be done in a non-obvious way:

(py. (py/get-item (py.. self -__class__ -__mro__) 1) __init__ self)

More feedback/research in this area is needed to integrated deeper into the python class hierarchies.

make-kw-instance-fn

(make-kw-instance-fn clj-fn & [{:keys [arg-converter result-converter], :or {arg-converter py-base/as-jvm}, :as options}])

Make an instance function - a function which will be passed the 'this' object as it's first argument. In this case the default behavior is to pass as-jvm bridged python object ptr args and kw dict args to the clojure function without marshalling. Self will be the first argument of the arg vector.

See options to libpython-clj2.python/make-callable.

Options:

  • :arg-converter - gets one argument and must convert into jvm space - defaults to as-jvm.
  • :result-converter - gets one argument and must convert to python space. Has reasonable default.

make-tuple-instance-fn

(make-tuple-instance-fn clj-fn & [{:keys [arg-converter], :or {arg-converter py-base/as-jvm}, :as options}])

Make an instance function - a function which will be passed the 'this' object as it's first argument. In this case the default behavior is to pass raw python object ptr args to the clojure function without marshalling as that can add confusion and unnecessary overhead. Self will be the first argument. Callers can change this behavior by setting the 'arg-converter' option as in 'make-tuple-fn'.

See options to libpython-clj2.python/make-callable.

py-fn->instance-fn

(py-fn->instance-fn py-fn)

Given a python callable, return an instance function meant to be used in class definitions.