Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3daf72a

Browse files
committed
Use __new__ magic method.
1 parent eba4b51 commit 3daf72a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

cybox/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ def from_obj(cls, cls_obj=None):
155155
elif issubclass(field.type_, Entity):
156156
val = field.type_.from_obj(val)
157157
else:
158-
#TODO: fix this
159-
val = field.type_.make(val)
158+
val = field.type_(val)
160159
setattr(entity, field.attr_name, val)
161160

162161
return entity
@@ -189,7 +188,7 @@ def from_dict(cls, cls_dict=None):
189188
val = field.type_.from_dict(val)
190189
else:
191190
#TODO: fix this
192-
val = field.type_.make(val)
191+
val = field.type_(val)
193192
setattr(entity, field.attr_name, val)
194193

195194
return entity

cybox/xs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class _type_base(object):
22
"""A base class for all of these types"""
33

4-
# TODO: get this working with python magic __new__ or __init__
5-
@classmethod
6-
def make(cls, val):
4+
_try_cast = True
5+
6+
def __new__(cls, val):
77
if val is None:
88
return None
99
return cls._pytype(val)

0 commit comments

Comments
 (0)