Quick search

The @overload decorator allows you to implement arbitrary functions
for use in nopython mode functions. The function decorated with
@overload is called at compile-time with the types of the function’s
runtime arguments. It should return a callable representing the
implementation of the function for the given types. The returned
implementation is compiled by Numba as if it were a normal function
decorated with @jit. Additional options to @jit can be passed as
dictionary using the jit_options argument.

For example, let’s pretend Numba doesn’t support the len() function
on tuples yet. Here is how to implement it using @overload:

You might wonder, what happens if len() is called with something
else than a tuple? If a function decorated with @overload doesn’t
return anything (i.e. returns None), other definitions are tried until
one succeeds. Therefore, multiple libraries may overload len()
for different types without conflicting with each other.

Finally, the @overload_attribute decorator allows implementing a data
attribute (or property) on a type. Only reading the attribute is possible;
writable attributes are only supported through the
low-level API.

The following example implements the nbytes attribute
on Numpy arrays: