Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(base): move name setting to trainable base
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Jul 19, 2019
1 parent 16f1a49 commit 12dfde4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions gnes/base/__init__.py
Expand Up @@ -83,16 +83,6 @@ def __call__(cls, *args, **kwargs):
v = kwargs[k]
setattr(obj, k, v)

if not getattr(obj, 'name', None):
_id = str(uuid.uuid4()).split('-')[0]
_name = '%s-%s' % (obj.__class__.__name__, _id)
obj.logger.warning(
'this object is not named ("- gnes_config: - name" is not found in YAML config), '
'i will call it as "%s". '
'naming the object is important especially when you need to '
'serialize/deserialize/store/load the object.' % _name)
setattr(obj, 'name', _name)

getattr(obj, '_post_init_wrapper', lambda *x: None)()
return obj

Expand Down Expand Up @@ -170,6 +160,16 @@ def __init__(self, *args, **kwargs):
self._post_init_vars = set()

def _post_init_wrapper(self):
if not getattr(self, 'name', None):
_id = str(uuid.uuid4()).split('-')[0]
_name = '%s-%s' % (self.__class__.__name__, _id)
self.logger.warning(
'this object is not named ("- gnes_config: - name" is not found in YAML config), '
'i will call it as "%s". '
'naming the object is important especially when you need to '
'serialize/deserialize/store/load the object.' % _name)
setattr(self, 'name', _name)

_before = set(list(self.__dict__.keys()))
self.post_init()
self._post_init_vars = {k for k in self.__dict__ if k not in _before}
Expand Down

0 comments on commit 12dfde4

Please sign in to comment.