Implementing a custom type
To implement a custom python-level type, one can use the :func:`py.type` builtin. At the JS-level, it is a function with the same signature as the :py:class:`type` builtin . It returns a child type of its one base (or :py:class:`py.object` if no base is provided).
- Functions which have been wrapped explicitly (via :class:`py.PY_def`, :py:class:`py.classmethod` or :py:class:`py.staticmethod`) are associated to the class untouched. But due to their wrapper, they will use the :ref:`types-methods-python-call` anyway
Python calling conventions
A callable following the :ref:`types-methods-python-call` must return a py.js object, an error will be generated when failing to do so.
Here is a list of the understood datamodel methods, refer to the relevant Python documentation for their roles.
Customizing attribute access
Emulating Numeric Types
- Non-in-place binary numeric methods (e.g. __add__, __mul__, ...) should all be supported including reversed calls (in case the primary call is not available or returns :py:data:`py.NotImplemented`). They take a single :py:class:`py.object` parameter and return a single :py:class:`py.object` parameter.
- Unary operator numeric methods are all supported:
- For non-operator numeric methods, support is contingent on the corresponding :ref:`builtins <builtins>` being implemented
Emulating container types