shotgunsoftware/tk-core — pull request #59 by manneohrstrom (2014-03-18 14:33:31+00:00)
Title: #24650 Support for inheritance in Hooks

Implements an optional, backwards compatible support for inheritance in hooks.

When new style hooks are used, it is now possible to construct the following custom hook:

```python
import sgtk

HookBaseClass = sgtk.get_hook_baseclass()

class DerivedHook(HookBaseClass):

def some_method(self, param):
data = HookBaseClass.some_method(self, param)
data.append("derived class stuff")
return data
```

The `sgtk.get_hook_baseclass()` will return the immediate parent class, allowing for flexible customization.

## Basic Use

For new-style hooks in the info.yml in the manifest (e.g. default values starting with `{self}`), inheritance will be gracefully handled. What this means is that if you have the following definition for your custom hook:

```
some_hook: '{config}/my_override.py'
```

The `sgtk.get_hook_baseclass()` call inside that `my_override.py` file will return the class that is defined in the default hook that comes bundled with the app.

## Advanced Use

It is also possible to create multiple levels of inheritance, using a ":" syntax. A complex example:

```
some_hook: '{tk-framework-perforce_v1.x.x}/path/to/foo.py:{config}/my_override.py'
```

This will generate three levels of inheritance; the perforce hook `foo.py` will inherit from the built-in hook, and then `my_override.py` will derive from the perforce hook.