Skip to content

Commit

Permalink
Rename create_object to instantiate (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
narumiruna authored Mar 13, 2020
1 parent 55c7506 commit 8ca75d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions mlconfig/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Config(AttrDict):

def __call__(self, *args, **kwargs):
return self.create_object(*args, **kwargs)
return self.instantiate(*args, **kwargs)

def save(self, f, **kwargs):
r"""Save configuration file
Expand All @@ -24,7 +24,7 @@ def save(self, f, **kwargs):
"""
save_dict(self.to_dict(), f, **kwargs)

def create_object(self, *args, recursive=False, ignore_args=False, **kwargs):
def instantiate(self, *args, recursive=False, ignore_args=False, **kwargs):
r"""Create object (or get function output) from config
Arguments:
Expand All @@ -42,7 +42,7 @@ def create_object(self, *args, recursive=False, ignore_args=False, **kwargs):
if recursive:
for k, v in kwargs.items():
if isinstance(v, self.__class__):
kwargs[k] = v.create_object(recursive=recursive, ignore_args=ignore_args)
kwargs[k] = v.instantiate(recursive=recursive, ignore_args=ignore_args)

func_or_cls = _REGISTRY[self[_KEY_OF_FUNC_OR_CLS]]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def test_save_and_load_config(self):
c2 = mlconfig.load(f)
self.assertDictEqual(c1.to_dict(), c2.to_dict())

def test_create_object(self):
def test_instantiate(self):
a = 1
b = 2
config = Config(name='AddOperator', a=a, b=b)

obj = config.create_object()
obj = config.instantiate()
self.assertEqual(obj.add(), a + b)

def test_call(self):
Expand Down

0 comments on commit 8ca75d5

Please sign in to comment.