Skip to content

Commit

Permalink
Reduced the creation time
Browse files Browse the repository at this point in the history
  • Loading branch information
quiqueporta committed Jan 15, 2019
1 parent 5c59448 commit 3c81500
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.2.0 (2019-01-15)
------------------

- Reduced the creation time

1.1.1 (2015-09-05)
------------------

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Test
> PYTHONPATH=$PYTHONPATH:. mamba
.. |Version Number| image:: https://img.shields.io/badge/version-1.1.1-blue.svg
.. |Version Number| image:: https://img.shields.io/badge/version-1.2.0-blue.svg

.. |Build Status| image:: https://travis-ci.org/quiqueporta/simple-value-object.svg?branch=master
:target: https://travis-ci.org/quiqueporta/simple-value-object
Expand Down
2 changes: 1 addition & 1 deletion simple_value_object/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .value_object import ValueObject
from .decorators import invariant

VERSION = (1, 1, 1, 'final')
VERSION = (1, 2, 0, 'final')
__version__ = VERSION


Expand Down
19 changes: 10 additions & 9 deletions simple_value_object/value_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,23 @@ def check_invariants():
)

def invariant_execute(invariant):
return_value = getattr(self, invariant)(self)
return_value = invariant(self, self)

if not isinstance(return_value, bool):
raise InvariantReturnValueException()

return return_value

def is_invariant(method):
try:
return 'invariant_func_wrapper' in str(method) and '__init__' not in str(method)
except TypeError:
return False

def obtain_invariants():
for member in inspect.getmembers(cls):
try:
is_method = hasattr(member[1], '__call__')
is_a_invariant_method = 'invariant_func_wrapper' in inspect.getsourcelines(member[1].__code__)[0][0]
if is_method and is_a_invariant_method:
yield(member[0])
except AttributeError:
continue
invariants = [member[1] for member in inspect.getmembers(cls, is_invariant)]
for invariant in invariants:
yield(invariant)

def check_mutable_data_types():
mutable_types = (list, dict, set)
Expand Down

0 comments on commit 3c81500

Please sign in to comment.