Skip to content

Commit

Permalink
Merge pull request #372 from hannesdelbeke/master
Browse files Browse the repository at this point in the history
add support for kwargs in instance init
  • Loading branch information
mottosso authored Oct 19, 2021
2 parents aaec8a8 + fc5f350 commit 4bfd6e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,7 @@ def create_instance(self, name, **kwargs):
"""

instance = Instance(name, parent=self)
instance.data.update(kwargs)
instance = Instance(name, parent=self, **kwargs)
return instance

def __getitem__(self, item):
Expand Down Expand Up @@ -820,10 +819,11 @@ class Instance(AbstractEntity):
"""

def __init__(self, name, parent=None):
def __init__(self, name, parent=None, **kwargs):
super(Instance, self).__init__(name, parent)
self._data["family"] = "default"
self._data["name"] = name
self._data.update(kwargs)

def __eq__(self, other):
return self._id == getattr(other, "id", None)
Expand Down
2 changes: 1 addition & 1 deletion pyblish/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

VERSION_MAJOR = 1
VERSION_MINOR = 8
VERSION_PATCH = 8
VERSION_PATCH = 9

version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
version = '%i.%i.%i' % version_info
Expand Down
8 changes: 8 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,14 @@ def process(self, context):
assert count["#"] == 11, count


def test_instance_kwarg_init():
# check if all kwargs get passed to the metadata dict of the instance
mock_families = ['mock_family1', 'mock_family2']
inst = pyblish.api.Instance(name='test', madeup_kwarg=13, families=mock_families)
assert inst.data['madeup_kwarg'] == 13
assert inst.data['families'] == mock_families


def test_actions_and_explicit_plugins():
"""Actions work with explicit plug-ins"""

Expand Down

0 comments on commit 4bfd6e1

Please sign in to comment.