Skip to content

Commit

Permalink
Added instance id as property of base class
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerkin committed May 4, 2018
1 parent 379f2cb commit 5c71f02
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sciunit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def json(self, add_props=False, keys=None, exclude=None, string=True,
result = json.loads(result)
return result

@property
def _id(self):
return id(self)

@property
def _class(self):
url = getattr(self.__class__,'remote_url','')
Expand Down Expand Up @@ -146,7 +150,8 @@ def default(self, obj):
o = obj._state(state=state, keys=self.keys, exclude=self.exclude)
elif isinstance(obj,(dict,list,tuple,str,type(None),bool,float,int)):
o = json.JSONEncoder.default(self, obj)
else: # Something we don't know how to serialize; just represent it as truncated string
else: # Something we don't know how to serialize;
# just represent it as truncated string
o = "%.20s..." % obj
return o

Expand All @@ -168,6 +173,7 @@ def weights(self):
weights = [1.0/n for i in range(n)]
return weights


def deep_exclude(state, exclude):
tuples = [key for key in exclude if isinstance(key,tuple)]
s = state
Expand Down

0 comments on commit 5c71f02

Please sign in to comment.